Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class SuperType {
- public int A;
- }
- public static class SubType extends SuperType {
- public int B;
- }
- public static class ParametricType<T> {
- public T Value;
- }
- @Test
- public void doNotSerializeSubClassFieldsTest() throws Exception {
- var mapper = new ObjectMapper();
- var writer = mapper.writerFor(SuperType.class);
- var subType = new SubType();
- subType.A = 1;
- subType.B = 2;
- var expectedValue = "{"A":1}";
- var data = writer.writeValueAsString(subType);
- assertEquals(expectedValue, data);
- }
- @Test
- public void serializeNotSubclassAuthenticatedMessageTest() throws Exception {
- var mapper = new ObjectMapper();
- var javaType = mapper.getTypeFactory().constructParametricType(ParametricType.class, SuperType.class);
- var writer = mapper.writerFor(javaType);
- var subType = new SubType();
- subType.A = 1;
- subType.B = 2;
- var parametricType = new ParametricType<>();
- parametricType.Value = subType;
- var expectedValue = "{"Value":{"A":1}}";
- var data = writer.writeValueAsString(parametricType);
- // it is actually "{"Value":{"A":1,"B":2}}"
- assertEquals(expectedValue, data);
- }
Add Comment
Please, Sign In to add comment