jackson-modules

How do I avoid content fields in Joda objects?

淺唱寂寞╮ 提交于 2019-12-04 04:21:20
问题 I'm using Joda objects (DateTime and DateTimeZone) in a document and whenever I access it via the REST interface I get entries with fields like this lastAggregationDate: { content: "2016-07-12T17:58:43.643Z" } instead of lastAggregationDate: "2016-07-12T17:58:43.643Z" I have the Joda Jackson dependencies declared and I see the de/serializers for these types so I'm puzzled as to what's at work here. I've duplicated this behavior in a slightly modified Spring sample project but using Java's

Jackson desrialize when JsonProperty is sometimes array and sometimes a single Object

时光毁灭记忆、已成空白 提交于 2019-12-04 02:37:30
I've searched Stack Overflow before posting, but there were no solutions for Jackson. Here is a server response: { "ok": true, "result": [ { "update_id": 489881731, //rest }, { "update_id": 489881732, //rest } ] } As you see property "result" is an array. Now this is another response: { "ok": true, "result": { "id": 211948704, "first_name": "ربات ادمین‌های تلگرام", "username": "tgAdminsBot" } } Here "result" is a single object. This is my class I want to deserialize content to it. I wrote a custom deserializer for TObject of course: public class Result { private TObject[] result; private

How to map the Mixins for the nested JSON response

落爺英雄遲暮 提交于 2019-12-03 13:45:06
I am using Jackson APIs for Mapping my JSON response into a java object . For example, for the response { name :'karthikeyan',age:'24',gender:'Male'} @JsonProperty("name") public String _name; @JsonProperty("age") public int _age; @JsonProperty("gender") public String _gender; is the Mix-in and it works fine.(internally we will be mapping this pojo and Mix-in). Now how can i represent the following response in a Mix-in? { name :'karthikeyan', age:'24', gender:'Male', interest: { books:'xxx', music:'yyy', movie:'zzz' } } i have tried with the following, but no luck. @JsonProperty("name") public

Generate JSON schema from java class

ぐ巨炮叔叔 提交于 2019-12-03 04:14:37
I have a POJO class public class Stock{ int id; String name; Date date; } Are there any annotations or development framework/api that can convert POJO to JSON schema like below {"id": { "type" : "int" }, "name":{ "type" : "string" } "date":{ "type" : "Date" } } and also i can expand the schema to add information like "Required" : "Yes", description for each field, etc., by specifying some annotations or configurations on POJO and can generate JSON Schema like below. {"id": { "type" : "int", "Required" : "Yes", "format" : "id must not be greater than 99999", "description" : "id of the stock" },

How do I avoid content fields in Joda objects?

狂风中的少年 提交于 2019-12-01 22:38:21
I'm using Joda objects (DateTime and DateTimeZone) in a document and whenever I access it via the REST interface I get entries with fields like this lastAggregationDate: { content: "2016-07-12T17:58:43.643Z" } instead of lastAggregationDate: "2016-07-12T17:58:43.643Z" I have the Joda Jackson dependencies declared and I see the de/serializers for these types so I'm puzzled as to what's at work here. I've duplicated this behavior in a slightly modified Spring sample project but using Java's native date types rather than Joda's. I've added a date of birth property to the Person object and

Jackson Modules for Map Serialization

老子叫甜甜 提交于 2019-12-01 16:31:11
I have a Class that contains a Map (with non String key) and some other fields. public class MyClass() { private Map<KeyObject, OtherObject> map; private String someField; public MyClass(Map<KeyObject, OtherObject> map, String someField) { this.map = map; this.someField = someField; } // Getters & Setters } I would like to serialize and deserialize this class using Jackson. I saw a different ways of doing that and decided to try using jackson modules . I followed this post and extended JsonDeserializer and JsonSerializer. The problem is that those classes should be typed, so it should look

Ignore fields only in json but not xml with jackson-dataformat-xml

懵懂的女人 提交于 2019-12-01 11:12:29
问题 Using jackson with the jackson-dataformat-xml module, I am able to serialize POJO to both json and xml. There are a few fields (xml attributes) in my object that should only be serialized to XML and not json. If I apply the @JsonIgnore annotation, the field is completely ignored even with @JsonXMLProperty. How can I ignore fields only in json but not xml? 回答1: You should use Mix-in feature. For example, assume that your POJO class looks like this: class Pojo { private long id; private String

@JsonCreator and mixin via Module not working for 3rd Party Class

时间秒杀一切 提交于 2019-12-01 10:45:36
I am trying to deserialize java.net.HttpCookie which doesn't have a default no-arg constructor and am getting: org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class java.net.HttpCookie]: can not instantiate from JSON object (need to add/enable type information?) at [Source: java.io.StringReader@5a395674; line: 1, column: 35 This is with jackson-mapper-asl v 1.9.13 I found Jackson 3rd Party Class With No Default Constructor and attempted to use their solution via both getDeserializationConfig and using module. I present the module code below.

Using jackson-dataformat-xml on android

﹥>﹥吖頭↗ 提交于 2019-11-30 08:38:49
问题 I'm strugling with using jackson-dataformat-xml on android I have some very basic code that works fine on oracle jre JacksonXmlModule module = new JacksonXmlModule(); module.setDefaultUseWrapper(false); XmlMapper xmlMapper = new XmlMapper(module); First I tried official documentation adapted for gradle (by me, not sure if done correctly): compile 'com.fasterxml.jackson.core:jackson-core:2.5.4' compile 'com.fasterxml.jackson.core:jackson-annotations:2.5.4' compile 'com.fasterxml.jackson.core

Generate Json Schema from POJO with a twist

无人久伴 提交于 2019-11-30 03:42:12
What I have: I'm generating a JSON schema from a pojo. My code to generate the schema looks like so: ObjectMapper mapper = new ObjectMapper(); TitleSchemaFactoryWrapper visitor = new TitleSchemaFactoryWrapper(); mapper.acceptJsonFormatVisitor(clazz, visitor); JsonSchema schema = visitor.finalSchema(); schemas.put(clazz, mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema)); I'm generating several schemas via the above code. One of the pojos has an internal embedded enum to limit the possible values, like so: public class MyClass { @JsonProperty("name") private String name;