Skip to content

Commit

Permalink
add testcase for issue #1990
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Nov 5, 2023
1 parent 95cb747 commit bb0282f
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.alibaba.fastjson2.issues_1900;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONFactory;
import com.alibaba.fastjson2.PropertyNamingStrategy;
import com.alibaba.fastjson2.writer.ObjectWriterProvider;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue1990 {
@Test
public void test() {
ObjectWriterProvider provider = JSONFactory.getDefaultObjectWriterProvider();

PropertyNamingStrategy namingStrategy = provider.getNamingStrategy();
try {
provider.setNamingStrategy(PropertyNamingStrategy.SnakeCase);
Bean bean = new Bean();
bean.userId = 123;
assertEquals("{\"user_id\":123}", JSON.toJSONString(bean));
} finally {
provider.setNamingStrategy(namingStrategy);
}
}

public static class Bean {
public int userId;
}
}

0 comments on commit bb0282f

Please sign in to comment.