Is there a way using Jackson JSON Processor to do custom field level serialization? For example, I’d like to have the class serialized to the follow JSON: Note that age=25 is encoded as a number while favoriteNumber=123 is encoded as a string. Out of the box Jackson marshalls int to a number. In this case I want favoriteNumber to be
Tag: jackson
My JSON files are too big to fit into memory, what can I do?
In my program, I am reading a series of text files from the disk. With each text file, I process out some data and store the results as JSON on the disk. In this design, each file has its own JSON file. In addition to this, I also store some of the data in a separate JSON file, which stores
Deserializing non-string map keys with Jackson
I have a a map that looks like this: My verb class looks like this: I want to serialize and deserialize instances of my VerbResult class, but when I do I get this error: Can not find a (Map) Key deserializer for type [simple type, class my.package.Verb] I read online that you need to tell Jackson how to deserialize map
Jackson overcoming underscores in favor of camel-case
I retrieve a JSON string from internet; like most JSON I’ve seen it includes long keys that are separated by underscores. Essentially, my goal is to deserialize JSON into java-objects, but I don’t use underscores in java-code. For instance, I might have a User class with firstName field in camel-case, simultaneously I need somehow to tell Jackson to map first_name
Different names of JSON property during serialization and deserialization
Is it possible: to have one field in class, but different names for it during serialization/deserialization in Jackson library? For example, I have class “Coordiantes”. For deserialization from JSON want to have format like this: But when I will serialize object, result should be like this one: I tried to implement this by applying @JsonProperty annotation both on getter and
Jackson JSON do not wrap attributes of nested object
I’ve got following classes: When I serialize Container class using Jackson I get But I need the result to be: Is it possible (without adding Container.getDataId() method)? If so, how to do it? update I’ve tried to create custom JsonSerializer<Data> but the result was same as before I’ve also tried to add @JsonSerialize annotation above Data class, then above getter
Can not find a (Map) Key deserializer for type [simple type, class …]
I have a domain object that has a Map: When I serialize the object, I get this: This Map’s key is a custom Object: So, I am not sure how to correct this exception I keep getting when I deserialize the object: How to correct this issue? I do not have access to the domain object to modify. Answer By
How to use Jackson to deserialise an array of objects
The Jackson data binding documentation indicates that Jackson supports deserialising “Arrays of all supported types” but I can’t figure out the exact syntax for this. For a single object I would do this: Now for an array I want to do this: Anyone know if there is a magic missing command? If not then what is the solution? Answer First
Deserializing JSON into object with overloaded methods using Jackson
I am attempting to deserialize a JSON object stored in CouchDb using Jackson. This object needs to deserialize into a pojo that contains overloaded methods. When I attempt to retrieve the object from couch and do the deserialization I get the following exception: org.ektorp.DbAccessException: org.codehaus.jackson.map.JsonMappingException: Conflicting setter definitions for property “multiplier”: com.db.commodities.framework.sdos.model.security.EqOpt#setMultiplier(1 params) vs com.db.commodities.framework.sdos.model.security.EqOpt#setMultiplier(1 params) I tried to annotate
Converting JSON data to Java object
I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string can look like: In this string every JSON object contains an array of other JSON objects. The intention is to extract a list of IDs