jackson

Using Jackson ObjectMapper to serialize the subclass name into JSON, not the superclass

In the following Jackson/Java code that serializes objects into JSON, I am getting this: {"animal":{"x":"x"}} However, what I actually want to get is this: {"dog":{"x":"x"}} Is there something I can do to AnimalContainer so that I get the runtime type ("dog", "cat") of the object, instead of "animal")? (Edit: I am aware that the ...

Issue Unmarshalling Map with JAX RS using JACKSON

Hi! I have a method definition as such: @POST @Path("save") @Consumes("application/json") public void save(Map<ClientVO, Map<AssessmentVO, String>> data){ System.out.println("THIS IS THE DATA: " + data); } When I try to unmarshall on the server, I get the following exception Exception in thread "main" org.jboss.resteasy....

How to generate JSON from a Jersey resource?

I'm using Jersy and want to output the following JSON with only the fields listed: [ { "name": "Holidays", "value": "http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic" }, { "name": "Personal", "value": "http://www.google.com/calendar/feeds/myprivatefeed/basic" ...

Spring 3.0 making JSON response using jackson message converter

i configure my messageconverter as Jackson's then class Foo{int x; int y} and in controller @ResponseBody public Foo method(){ return new Foo(3,4) } from that i m expecting to return a JSON string {x:'3',y:'4'} from server without any other configuration. but getting 404 error response to my ajax request If the method is an...

Jackson Vs. Gson

After searching through some existing libraries for JSON, I have finally ended up with these two: Jackson Google GSon I am a bit partial towards GSON, but word on the net is that GSon suffers from certain celestial performance issue. I am continuing my comparison, in the meanwhile I was looking for help to make up my mind. ...

Use class name as root key for JSON Jackson serialization

Suppose I have a pojo: public class MyPojo { int id; public int getId() { return this.id } public setId(int id) { this.id = id } public static void main(String[] args){ MyPojo mp = new MyPojo(); mp.setId(4); ObjectMapper mapper = new ObjectMapper(); mapper.getSerializationConfig().set(Serializat...

JSON: Jackson stream parser - is it really worth it?

I'm making pretty heavy use of JSON parsing in an app I'm writing. Most of what I have done is already implemented using Android's built in JSONObject library (is it json-lib?). JSONObject appears to create instances of absolutely everything in the JSON string... even if I don't end up using all of them. My app currently runs pretty w...

Java Jackson: Example of @JsonTypeResolver usage

Could not find any examples of @JsonTypeResolver usage in the docs or elsewhere. ...

Using Jackson as Jersey client serializer

Is it possible to use Jackson as the serializer/marshaller for JSON data instead of JAXB when using Jersey Client API? If so how to configure it? ...

Replace standard Android JSON parser for better performance?

I know that Android has a JSON parser baked in but I was wondering if it was worth using something that offered better performance (like Jackson - see http://jackson.codehaus.org/) ? Anybody tried that ? ...

Possible to configure Jackson-Json Mapper to exclude properties based on which object it is serializing?

Say I have objects such as a Business with a List of Address objects, and an Order that has a Business. Is it possible to configure so that when the Order is serialized it excludes the list of addresses from the Business object, and when the business is serialized it includes the list? I'm using ajax to pull data for an RIA and when wo...

How to convert a JSON string to a Map<String, String> with Jackson JSON

This is my first time trying to do something useful with Java.. I'm trying to do something like this but it doesn't work: Map<String, String> propertyMap = new HashMap<String, String>(); propertyMap = JacksonUtils.fromJSON(properties, Map.class); But the IDE says: 'Unchecked assignment Map to Map<String,String>' What's the right wa...

Json Jackson deserialization without inner classes

Hi everyone, I have a question concerning Json deserialization using Jackson. I would like to deserialize a Json file using a class like this one: (taken from http://wiki.fasterxml.com/JacksonInFiveMinutes) public class User { public enum Gender { MALE, FEMALE }; public static class Name { private String _first, _last; ...

Handling Unknown JSON Properties with Jackson

Hi, For deserializing json with unknown field into an object there's @JsonAnySetter. But what if I read such json into my object, modify some known fields and write it back to json? The unknown properties will be lost. How do I handle such cases? Is it possible to map an object or do I have to read the data into a JsonNode or Map? ...

Warning: This class was probably produced by a broken compiler.

I have added Jacson libs to my android project and now I am getting such warnings in console: warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.) I've tried to recompile libs, but it didn't...

Jackson - suppressing serialization(write) of properties dynamically

I am trying to convert java object to JSON object in Tomcat/jersey using Jackson. And want to suppress serialization(write) of certain properties dynamically. I can use JsonIgnore, but I want to make the ignore decision at runtime. Any ideas?? So as an example below, I want to suppress "id" field when i serialize the User object to JSO...

Android compatibility with Restlet/JSON/Jackson

I'm currently working on a webservice-client for Android. I'm using a Java client library which provides an abstraction for interaction with the service. The client library works on normal machines. However, when I use the classes in my Android project, some calls don't return a result on Android, the background-service stops working at ...

How to do peek() in Jackson json library?

I'm using the Streaming API JsonParser of the Jackson library to do some custom json parsing in java. Is there a way of achieving functionality similar to a peek() method, where the next token is returned but the cursor position is not moved forward? The use case for this is similar to the following: JsonParser parser = new JsonFactor...

Jackson not recognizing @JsonCreator annotation

I am currently using Jackson 1.4.2 and attempting deserialization of 'code' values (unique identifiers for type information) that are passed from our UI back to the Java controllers (Servlets). There are multiple types (e.g. ABCType, XYZType, etc.) that all extend from an AbstractType, but each concrete type has a static factory method...

How to avoid null values serialization in HashMap?

I would like to serialize a HashMap as a string through the Jackson JSON processor. For example: String strMap = getMapper().writeValueAsString(myHashMap); result output -> {"r_id":6,"a_am":null,"smb":"Submit","a_li":null,"l_id":878,"pos":[1345,1346,1347]} I don't know how to disable null values serialization for Map. It works fine on...