Using Jackson to convert a Java object to JSON
ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); jsonMessage = mapper.writeValueAsString(object);
the result is that the participants field (which is part of the object instance)
participants Arrays$ArrayList<E>
renamed to "membersList"
participantsList":[{"userId":"c1f9c"}]
i.e. A list is added to the field name. I looked through Jackson's documentation, but found no way to prevent this. Is it possible? Testing the above code in a separate project does not lead to the same result (i.e. renaming does not occur). Why is Jackson acting like this? Unfortunately, the object is a third party, and I cannot change it.
Using Jackson's 2.3.3 version (the same behavior is confirmed since 2.9.0).
java json jackson objectmapper
heeboir
source share