jackson-modules

How to disable JsonProperty or JsonIgnore on test

此生再无相见时 提交于 2021-01-27 09:34:07
问题 If there a way to disable @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) or @JsonIgnore on testing? I am trying to test my createUser() but I need user.getPassword() method be enabled when I parse my User object. If I comment the @JsonProperty line it works but if that I do so, the password field will be returned on GET /users or GET /users/{id} method. Here is my test @Test public void createUser() throws Exception { User user = UserFactory.newUser(); String userJson = objectMapper

How can I register and use the jackson AfterburnerModule in Spring Boot?

China☆狼群 提交于 2020-12-30 08:54:55
问题 I am using SpringBoot 1.5.9., Jackson 2.8 and Spring Framework 4.3.13. I am trying to register and use the AfterburnerModel. According to the Spring Boot documentation, to configure the ObjectMapper you can either define the bean yourself and annotate it with @Bean and @Primary. In the bean you can register a module. Or you can add a bean of type Jackson2ObjectMapperBuilder where you can customize the ObjectMapper, by adding a module. I have tried both ways, and during serialization none of

How can I register and use the jackson AfterburnerModule in Spring Boot?

≯℡__Kan透↙ 提交于 2020-12-30 08:54:25
问题 I am using SpringBoot 1.5.9., Jackson 2.8 and Spring Framework 4.3.13. I am trying to register and use the AfterburnerModel. According to the Spring Boot documentation, to configure the ObjectMapper you can either define the bean yourself and annotate it with @Bean and @Primary. In the bean you can register a module. Or you can add a bean of type Jackson2ObjectMapperBuilder where you can customize the ObjectMapper, by adding a module. I have tried both ways, and during serialization none of

CharConversionException in parsing CSV file using Jackson's CSV data format module

核能气质少年 提交于 2020-05-13 07:10:15
问题 I am trying to parse CSV file using Jackson's CSV data format module. I tried sample code given on their project homepage (https://github.com/FasterXML/jackson-dataformat-csv) CsvMapper mapper = new CsvMapper(); mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY); File csvFile = new File("input.csv"); MappingIterator<String[]> it = mapper.reader(String[].class).readValues(csvFile); while (it.hasNext()) { String[] row = it.next(); System.out.println(row) } this small code is giving me error

CharConversionException in parsing CSV file using Jackson's CSV data format module

落花浮王杯 提交于 2020-05-13 07:06:15
问题 I am trying to parse CSV file using Jackson's CSV data format module. I tried sample code given on their project homepage (https://github.com/FasterXML/jackson-dataformat-csv) CsvMapper mapper = new CsvMapper(); mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY); File csvFile = new File("input.csv"); MappingIterator<String[]> it = mapper.reader(String[].class).readValues(csvFile); while (it.hasNext()) { String[] row = it.next(); System.out.println(row) } this small code is giving me error

Jackson Java 8 DateTime serialisation

▼魔方 西西 提交于 2020-01-04 17:51:10
问题 Jackson operates java.time.Instant with WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS ( READ_ as well) enabled by default. jackson-datatype-jsr310 It produces JSON like this { "createDate":1421261297.356000000, "modifyDate":1421261297.356000000 } In JavaScript it's much easier to get Date from traditional millis timestamp (not from seconds/nanos as above), like new Date(1421261297356) . I think there should be some reason to have the nanos approach by default, so what is that reason? 回答1: One way is

set Jackson ObjectMapper class not to use scientific notation for double

三世轮回 提交于 2019-12-28 17:44:59
问题 I am using a library com.fasterxml.jackson library for JsonSchema, I am creating creating an IntegerSchema object, when I set range for integer schema using below code: main(){ IntegerSchema intSchema = new IntegerSchema(); // setMaximum accepts Double object intSchema.setMaximum(new Double(102000000)); // setMaximum accepts Double object intSchema.setMinimum(new Double(100)); printJsonSchema(intSchema); } public void printJsonSchema(JsonSchema schema){ ObjectMapper mapper = new ObjectMapper(

Jackson: Serialize null object as empty

岁酱吖の 提交于 2019-12-22 11:28:27
问题 I have huge json document and appropriate jaskson models that are mapped to that json. In some cases it is not possible to build the required json document with all object because some data does not exist. for instance I have following models: class First { private firstField; private secondField; etc... } class Second { private firstField; private secondField; etc... } class General { private First first; private Second second; etc... } And there is possibility to populate only First

Using Jackson in Jersey with multiple configured ObjectMappers

☆樱花仙子☆ 提交于 2019-12-22 04:04:11
问题 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

Jackson Modules for Map Serialization

青春壹個敷衍的年華 提交于 2019-12-19 17:45:21
问题 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