jackson-modules

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

旧城冷巷雨未停 提交于 2019-12-19 10:16:18
问题 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

Generate Json Schema from POJO with a twist

徘徊边缘 提交于 2019-12-18 11:28:51
问题 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

Writing Java object instance to YAML using Jackson

邮差的信 提交于 2019-12-18 06:39:07
问题 I have a 'Example' Pojo class as mentioned below. Can any one tel to save instance of Example class to YAML file using Jackson. public class Example { String name; int value; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } } 回答1: Jackson has a module that supports YAML. Ensure that you add the required dependency to your project, then you can use it

jackson - do not serialize lazy objects

筅森魡賤 提交于 2019-12-17 11:14:13
问题 I have an entity: @Entity public class Book { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; @Column private String title; @OneToMany(fetch = FetchType.LAZY, mappedBy = ("movie"),cascade = CascadeType.ALL) private List<Genre> genre; } Then I have a controller whose purpose is to retrieve books, my problem is that, the genre field is being included in the json response of my controller. Any way I can exclude those fields that are lazy loaded when jackson serializes the

deserializing CDATA with JacksonXML - UnrecognizedPropertyException

独自空忆成欢 提交于 2019-12-13 07:13:07
问题 I am using jackson libraries (2.5.2) and trying to deserialize some XML that actually has CDATA section. It seems that Jackson 2.5 added support for CDATA. Here is my class that has the CDATA: public class Certificate { @JacksonXmlProperty(localName = "name", isAttribute = true) private String name; @JacksonXmlCData private String data; @JacksonXmlProperty(localName = "date-added", isAttribute = true) @JsonFormat(pattern = "EEE MMM d HH:mm:ss z yyyy") private Date dateAdded; @JsonFormat

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

你离开我真会死。 提交于 2019-12-12 08:34:33
问题 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

Must we use @JsonProperty in Scala case classes?

北慕城南 提交于 2019-12-12 03:31:47
问题 everyone. This seems to be quite an unnecessary exercise to define the @JsonProperty annotations for Json serialization of a case class. For example: case class Foo @JsonCreator()( @JsonProperty("a") a: String, @JsonProperty("b") b: Boolean, @JsonProperty("c") c: Int) It appears that the trivial @JsonProperty annotations like this (just repeating the parameter's name) can be avoided in Java, by using the jackson-module-parameter-names module and the -parameters javac option: Why when a

Using Jackson in Jersey with multiple configured ObjectMappers

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 01:31:09
Is it possible to setup Jersey using Jackson for serialization/deserialization using multiple configured ObjectMappers ? What I would like to be able to do is register a "default" Jackson ObjectMapper and then have the ability to register another feature which provides an ObjectMapper with some specialized configuration which under certain circumstance will "override" the "default" ObjectMapper . For example, this ContextResolver would be for the "default" mapper: @Provider @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public class JacksonMapperProvider implements

How to map the Mixins for the nested JSON response

眉间皱痕 提交于 2019-12-04 22:00:12
问题 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',

Generate JSON schema from java class

一个人想着一个人 提交于 2019-12-04 09:52:30
问题 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",