deserialize to static List<T> field get double repeat value
See original GitHub issueTestcase:
public class Test {
private static final ObjectMapper MAPPER = new ObjectMapper();
static {
MAPPER.registerModule(new JodaModule());
MAPPER.registerModule(new JodaTimeModule());
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MAPPER.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true);
MAPPER.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
MAPPER.configure(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
protected static List<String> list = new ArrayList();
protected static String str = "str";
public List<String> getList() {
return list;
}
public String getStr() {
return str;
}
public static void main(String[] args) {
Test test = new Test();
test.getList().add("1");
String jsonString = MAPPER.writeValueAsString(test);
System.out.println(jsonString);
Test test1 = MAPPER.readValue(jsonString, Test.class)
System.out.println(test1.getList());
System.out.println(test1.getStr());
}
}
Result: {“str”:“str”,“list”:[“1”]} [1, 1] str
I am very confused why “list” value change to double repeat value. if execute “writeValueAsString” and “readValue” multiple times, each will double for the result
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Json.net deserializing list gives duplicate items - Stack Overflow
In my code sample below I serialize an object, containing three types of simple integer lists (property, member var and array). The resulting ......
Read more >Ho to dynamically deserialize untyped a JSON with list
A JSON list deserializes to a List<Object> . At run time, the contents of the List (the Object instances) will have a type...
Read more >Duplicate field when serializing: bug or not a bug?
Hello, I have had a request for one of my projects to implement Jackson serialization of my JSON Patch implementation; deserialization was already...
Read more >How can I store deserialized objects in a List? - CodeRanch
I have created outside of any method (at the top of this class) an ArrayList from the type 'StagingAreaItem', which is a class...
Read more >JSON Deserialization in Salesforce - Blog - Deadlypenguin
I have been several posts recently on the Developer Boards around JSON ... id="invoiceBlock" columns="1"> <apex:repeat value="{!wrapper.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@cowtowncoder cool!! I think this is what I want, Thanks!!