Giter VIP home page Giter VIP logo

jackson-docs's Introduction

This project is the main hub to all kinds of documentation related to the Jackson JSON Processor.

Tutorials

For your first steps in understanding how to use Jackson, following tutorials are good places to start:

General

Annotations

Frameworks, Platforms

JVM Languages beyond Java

(need links to Scala, Kotlin, Clojure tutorials, articles)

Other

Documentation under Jackson GH projects

Jackson project hub has links to all active Jackson projects. These projects contain plenty of project-specific documentation, such as:

External (off-GitHub) documentation

Blogs that regularly write about Jackson include:

And here are good articles around the web:

Participating

The easiest ways to participate is to join one of Jackson mailing lists (Jackson google groups):

  • Jackson Announce: Announcement-only list for new Jackson releases, meetups and other events related to Jackson
  • Jackson User: List dedicated for discussion on Jackson usage
  • Jackson Dev: List for developers of Jackson core components and modules, discussing implementation details, API changes.

There are other related lists and forums as well:

Sample code

See (External) Jackson Sample Code.

On Jackson versioning

Note that there are two major Jackson versions: 1.x (1.0 - 1.9) and 2.x (2.0 - 2.13). These versions can co-exist as they are located in different Java packages and use different jar naming and Maven group/artifact ids. But this means that you have to make sure that all components in use have matching major versions: specifically, Jackson 2.x code does NOT understand or support Jackson 1.x annotations, or vice versa.

Minor versions (like 2.1 and 2.2) are backwards compatible with respect to public API: old code should work without recompilation, if (but only if) it relies on external API; public methods, annotations. When overriding internal functionality, we try hard to maintain backwards compatibility between adjacent minor versions; need for changes is indicated by deprecating internal methods. Recompilation is thus recommended when extending by sub-classing, for example.

Misc other

jackson-docs's People

Contributors

cowtowncoder avatar fzhyzamt avatar tatu-at-salesforce avatar tedblob avatar xenoamess avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jackson-docs's Issues

Possible useful name pattern for PTH documentation

This is not a solution for every use case, in large part because the Reflections scan can take some time, but it's a pattern that may be generally applicable enough to describe in the documentation:

  • Define an annotation for the subtypes, and meta-annotate with @JsonTypeName:
@JsonTypeName
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface FoocorpJsonType {
}
  • Use @FoocorpJsonType on all subtypes to be registered with the mapper:
@FoocorpJsonType
public class ConcreteMessage extends AbstractMessage {}
  • In a suitable location (such as a @PostConstruct method on a Spring configuration class, or wherever the ObjectMapper is built), use the org.reflections:reflections package and this magic spell:
Reflections reflections = new Reflections(
    ConfigurationBuilder.build("com.foocorp.base.package")
);

mapper.registerSubtypes(reflections.getTypesAnnotatedWith(FoocorpJsonType.class).toArray(new Class[0]));

This will scan the classpath (limited for performance) for types annotated with the custom annotation and register them all with the mapper so they can be deserialized when seen.

Update Jackson Mixin description

This page, https://github.com/FasterXML/jackson-docs/wiki/JacksonMixInAnnotations, says to use

objectMapper.getSerializationConfig().addMixInAnnotations(Rectangle.class, MixIn.class);
objectMapper.getDeserializationConfig().addMixInAnnotations(Rectangle.class, MixIn.class);

However, objectMapper.get*Config() returns an immutable object. The documentation also implies that there is one set of mixins for serialization and one for deserialization. This does not appear to be the case anymore.

Mapping issues with Java 8 java.time.Instant

How do you solve this:

com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class java.time.Instant]: can not instantiate from JSON object (need to add/enable type information?)

Thanks.

Boolean value not ignored through mix-in annotation

I am seeing an issue while using mix-in.

`public class A {
@JsonIgnore
boolean property1;
String property2;
}

ObjectMapper mapper = new ObjectMapper();
when serializedmapper.writeValueAsString(this)gives me result as {"property2" : value}and on Deserialization gives meA@ {property2:value}` but when I try to do the same thing using mix-in-annotation using a mix-in like this -:

public class MixIn { @JsonIgnore boolean property1; } mapper.addMixIn(A.class, MixIn.class);
serialization gives me result as {"property2" : value} however Deserialization -: mapper.readValue( {"property2" : value}) gives me A@ {property1 : false , property2:value } i.e. the boolean property is set to its default which I do not want. Can someone tell me what am I missing ?

How to serialize values which are provided JsonInclude.Include.NON_NULL at class level

Currently my application has a class which is as below

 @JsonInclude(JsonInclude.Include.NON_NULL)
  public class Employee {
     Department department;
     String firstName;
     String lastName;
     String address;
     String phoneNumber;
  }

I am capturing the employee object inside the logs where I am converting the object into JSON. I am able to convert the object to JSON but the null values do not get into the JSON.

I have tried the below

 objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
 generator.setCodec(objectMapper);
 generator.writeObjectField(fieldName, argument);

But not able to get the null values of the fields in JSON. How do I get them?

Add security warnings

Before posting here the details of the security warnings we think should be added to Jackson documentation, is there any private email address we can send the details to?

Thanks,
A

Upgrade to 2.12.4, default deserialization to 1970-1-1 if the date is null

Spring Boot was upgraded to 2.5.4, Jackson 2.12.4, and the default value of 1970-1-1 was deserialized when no value was passed in the date field in the XML message. I didn't find a way to configure the solution. I had to choose to downgrade the Jackson version and currently use 2.9.10 to fix the 1970 default date.

Provide Benchmarks

I know some people frown upon benchmarks provided by the core team, but it's very hard to properly benchmark on Java, since the JVM needs proper warm-up and etc and most if not all the benchmarks on the internet comparing Jackson to GSON appears to be wrong (check the comments section, everyone of them have a valuable point about what's wrong).

The HikariCP project provides it's own benchmarks and explains on it's documentation about the right way to test the library. This is very important since public articles can spread misinformation just for not knowing the proper way to use the library, to take advantage of its optimizations (let alone how to benchmark in java or use the JMH).

Providing benchmarks on the library only adds to end information, if the readers want an external opinion, they can feel free to look for outside benchmarks if they want to, so no negative downsides to this, the worst thing that can happen is raising the level of external benchmarks.

custom serialization of map attributes

I have an object with a map attribute with nested keys, e.g.

  • k1 ->
    • nested11 -> value11
    • nested12 -> value12
  • k2 ->
    • nested21 -> value21
    • nested22 -> value22

I need it to be serialized to JSON in a flattened manner, i.e.:

{
  "k1.nested11": "value11",
  "k1.nested12": "value12",
  "k2.nested21": "value11",
  "k2.nested22": "value22",
}

Is there anyway to achieve this without using custom serialization to the entire object?
I thought of some combination of @JsonAnyGetter and @JsonSerialize, but it does not work.

Here's what I tried in my custom serializer for the Map property:

    @Override
    public void serialize(Map<String, Object> map, 
                           JsonGenerator jgen, 
                          SerializerProvider provider) 
                throws IOException, JsonProcessingException
 {
        map.forEach((k, v) -> {
            try {
                jgen.writeObjectField(k, v);
            } catch (IOException e) {
                logger.warn("problem serializing field [" + k + "] with value [" + v+"]", e);
            }
        });
    }

I am getting the following error message:

2016-09-05 10:51:08,348 [main] WARN  MapJsonSerializer - problem writing field [swapLegs.1.nested1_k1] with value [nested1_v1]
com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value
    at com.fasterxml.jackson.core.base.GeneratorBase._reportError(GeneratorBase.java:412)
    at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator.writeFieldName(WriterBasedJsonGenerator.java:195)
    at com.fasterxml.jackson.core.JsonGenerator.writeObjectField(JsonGenerator.java:1018)

Am I using jgen.writeObjectField(k, v) incorrectly?
Can I call it a few times and add several properties?

Main Jackson README is beind on latest versions

Since https://github.com/FasterXML/jackson doesn't appear to allow issues to be reported against it…

The main README for the Jackson project is behind on what the latest version is. As of this writing, 2.15.2 is the latest version deployed to Maven Central. However, the README is behind the times in a few places, stating that 2.13.4 as being the latest released version:

What is New?

  • Nov 2, 2022: AdaLogics Security Audit for Jackson released -- see Document/Reports
  • Oct 28, 2022: Jackson 2.14 Release Candidate 3 (2.14.0-rc3) released; 2.14.0 itself soon to be released!
  • Sep 3, 2022: Jackson 2.13.4 patch released
  • Sep 30, 2021: Jackson 2.13.0 (new stable) released
  • Oct 1, 2020: Jackson participates in Hacktoberfest2020 and we have a Jackson/Hacktoberfest repo too!
  • Oct 9, 2020: Added Contributing

Actively developed versions

Jackson suite has two major versions: 1.x is deprecated and no versions are released;
2.x is the actively developed version.
These two major versions use different Java packages and Maven artifact ids, so they are not mutually compatible, but can peacefully co-exist: a project can depend on both Jackson 1.x and 2.x, without conflicts.
This is by design and was chosen as the strategy to allow smoother migration from 1.x to 2.x.

The latest stable versions from these branches are:

  • 2.13.4, released on 3-Sept-2022
    • 2.12.7 is the latest patch from previous stable branch
  • 1.9.13, released 14-Jul-2013

Active developed Jackson 2.x branches

Currently Jackson 2.x repositories have following actively developed branches:

  • 2.14: next minor version being developed (as of May 2022)
  • 2.13: current stable, actively maintained branch from which one more patch release is possible
  • 2.12: previous stable branch, only micro-patches likely to be released
  • master: next major version, 3.0. Still changing rapidly

Ideally, the README.md file should be brought up to date, and processes would be put in place to prevent it falling back out of date as new versions are released.

Documentation of mixins is obsolete. Adding mixins has no effect.

The documentation at http://wiki.fasterxml.com/JacksonMixInAnnotations explains that to use mixin annotations, one should do

objectMapper.getSerializationConfig().addMixInAnnotations(Target.class, MixIn.class);

But there is no such method in objectMapper.getSerializationConfig() (v2.2.3)

Moreover, trying to add mixin directly to the object mapper (using http://fasterxml.github.io/jackson-databind/javadoc/2.2.0/com/fasterxml/jackson/databind/ObjectMapper.html#addMixInAnnotations%28java.lang.Class,%20java.lang.Class%29 not only modifies the ObjectMapper, but has 0 effect. I had to copy the ObjectMapper and use the created copy to have the annotations applied. To apply mixin annotations for a given serialization, using a shared, reusable ObjectMapper, you thus need to

  • copy the shared ObjectMapper to avoid modifying it
  • add mixin annotations to the copy
  • create a copy of the copy to have the mixin annotations applied to the serialization configuration
  • use the copy of the copy to serialize

Maybe I missed something, but given the incorrect documentation, that's the only way I found to use mixins, and it's very far from being optimal.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.