How to parse a JSON string into JsonNode in Jackson?

It should be so simple, but I just cannot find it after being trying for an hour. I need to get a JSON string, for example, {“k1″:v1,”k2”:v2}, parsed as a JsonNode. JsonFactory factory = new JsonFactory(); JsonParser jp = factory.createJsonParser(“{\”k1\”:\”v1\”}”); JsonNode actualObj = jp.readValueAsTree(); gives java.lang.IllegalStateException: No ObjectCodec defined for the parser, can not deserialize … Read more

Jackson enum Serializing and DeSerializer

I’m using JAVA 1.6 and Jackson 1.9.9 I’ve got an enum public enum Event { FORGOT_PASSWORD(“forgot password”); private final String value; private Event(final String description) { this.value = description; } @JsonValue final String value() { return this.value; } } I’ve added a @JsonValue, this seems to do the job it serializes the object into: {“event”:”forgot … Read more

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: { ‘title’: ‘ComputingandInformationsystems’, ‘id’: 1, ‘children’: ‘true’, ‘groups’: [{ ‘title’: ‘LeveloneCIS’, ‘id’: 2, ‘children’: ‘true’, ‘groups’: [{ … Read more

Serializing with Jackson (JSON) – getting “No serializer found”?

I get the an exception when trying to serialize a very simple object using Jackson. The error: org.codehaus.jackson.map.JsonMappingException: No serializer found for class MyPackage.TestA and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) Below is the simple class and code to serialize. Can anyone tell my why I get this error? … Read more

Should I declare Jackson’s ObjectMapper as a static field?

The Jackson library’s ObjectMapper class seems to be thread safe. Does this mean that I should declare my ObjectMapper as a static field like this class Me { private static final ObjectMapper mapper = new ObjectMapper(); } instead of as an instance-level field like this? class Me { private final ObjectMapper mapper = new ObjectMapper(); … Read more

JsonMappingException: No suitable constructor found for type [simple type, class ]: can not instantiate from JSON object

I am getting the following error when trying to get a JSON request and process it: org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class com.myweb.ApplesDO]: can not instantiate from JSON object (need to add/enable type information?) Here is the JSON I am trying to send: { “applesDO” : [ { “apple” : “Green … Read more