Skip to content
Advertisement

Tag: jackson

Jackson JSON custom serialization for certain fields

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

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

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

Advertisement