Codebase list jackson-jr / upstream/2.12.1
New upstream version 2.12.1 Emmanuel Bourg 3 years ago
13 changed file(s) with 103 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
22 Jackson jr is a compact alternative to full [Jackson Databind](../../../jackson-databind) component.
33 It implements a subset of functionality, for example for cases where:
44
5 1. Size of jar matters (jackson-jr size is about 100 kB)
6 2. Startup time matters (jackson-jr has very low initialization overhead)
5 1. Size of jar matters (`jackson-jr-objects` is bit over 100 kB)
6 2. Startup time matters (`jackson-jr` has very low initialization overhead)
77
88 In addition to basic datatypes (core JDK types like `List`s, `Map`s, wrapper types),
99 package supports reading and writing of standard Java Beans (implementation that mimics standard
1010 JDK Bean Introspection): that is,
11 subset of POJOs that define setters/getters (starting with Jackson-jr `2.8`)
12 you can alternatively use `public` fields).
13
14 Jackson jr also adds `composer` implementation that can be used to
11 subset of POJOs that define setters/getters and/or `public` fields.
12 And with 2.11 there is even optional support for a subset of Jackson annotations
13 via optional `jackson-jr-annotatin-support` extension.
14
15 Jackson-jr also adds `composer` implementation that can be used to
1516 construct JSON output with builder-style API, but without necessarily having
1617 to build an in-memory representation: instead, it can directly use `streaming-api`
1718 for direct output. It is also possible to build actual in-memory
1819 JSON `String` or `byte[]` representation, if that is preferable.
1920
20 Jackson jr artifact itself is currently about 95 kB in size, and only depends on
21 Main Jackson-jr artifact (`jackson-jr-objects`) itself is currently about 120 kB in size, and only depends on
2122 [Jackson Streaming API](../../../jackson-core) package.
22 Combined size, for "all" jar, is about 400 kB (of which streaming API is about 300 kB),
23 Combined size, for "all" jar, is bit over 500 kB (of which streaming API is about 350 kB),
2324 for use cases where a single jar is preferred over more modular approach.
2425 Finally, use of jar minimizers like [ProGuard](http://proguard.sourceforge.net/) can bring the jar
2526 size down even further, by renaming and removing debug information.
9293 ```
9394
9495 (writing of `List`s and arrays works without addition effort: just pass List/array as-is)
96
97 ### Reading "streaming JSON" (LD-JSON)
98
99 Version 2.10 added ability to read [Streaming JSON](https://en.wikipedia.org/wiki/JSON_streaming) content.
100 See ["Jackson 2.10 features"](https://medium.com/@cowtowncoder/jackson-2-10-features-cd880674d8a2) (section "Jackson-jr feature expansion") for full example, but basic
101 reading is done using new `ValueIterator` abstraction:
102
103 ```
104 File input = new File("json-stream.ldjson");
105 try (ValueIterator<Bean> it = JSON.std.beanSequenceFrom(Bean.class, input)) {
106 while ((Bean bean = it.nextValue()) != null) {
107 // do something with 'bean'
108 }
109 }
110 ```
95111
96112 ### Writing with composers
97113
159175
160176 To support readability and writability of your own types, your Java objects must either:
161177
162 * Implement Bean style accesors (getters for accessing data to write and/or setter for binding JSON data into objects), and define no-argument (default) constructor, OR
178 * Implement Bean style accessors (getters for accessing data to write and/or setter for binding JSON data into objects), and define no-argument (default) constructor, OR
163179 * Define single-argument constructor if binding from JSON String (single-String argument) or JSON integer number (single-`long` or `Long` argument)
164180
165181 Note that although getters and setters need to be public (since JDK Bean Introspection does not find any other methods),
166182 constructors may have any access right, including `private`.
167183
168 Also: starting with version 2.8, `public` fields may also be used (although their
184 Starting with version 2.8, `public` fields may also be used (although their
169185 discovery may be disabled using `JSON.Feature.USE_FIELDS`) as an alternative:
170186 this is useful when limiting number of otherwise useless "getter" and "setter"
171187 methods.
188
189 NEW! Jackson-jr 2.11 introduce `jackson-jr-annotation-support` extension (see more below)
190 which allows use of Jackson annotations like `@JsonProperty`, `@JsonIgnore` and even `@JsonAutoDetect` for even more granular control of inclusion, naming and renaming.
172191
173192 ### Customizing behavior with Features
174193
181200 .asString(...);
182201 ```
183202
203 ### Adding custom value readers, writers
204
205 Version 2.10 added ability to add custom `ValueReader`s and `ValueWriter`s, to
206 allow pluggable support for types beyond basic JDK types and Beans.
207
208 See section "Jackson-jr ValueReaders" of [Jackson-jr 2.10 improvements](https://cowtowncoder.medium.com/jackson-2-10-jackson-jr-improvements-9eb5bb7b35f) for an explanation of how to add custom `ValueReader`s and `ValueWriter`s
209
210 You can also check out unit test
211
212 jr-objects/src/test/java/com/fasterxml/jackson/jr/ob/impl/CustomValueReadersTest.java
213
214 for sample usage.
215
216 ### Using (some of) Jackson annotations
217
218 Jackson 2.11 added a new extension (a `JacksonJrExtension`) -- `jr-annotation-support` -- that adds support for a subset of Jackson annotations.
219 See [jr-annotation-support/README.md](../../tree/master/jr-annotation-support) for details of this extension, but basic usage is by registering extension:
220
221 ```
222 import com.fasterxml.jackson.jr.annotationsupport.JacksonAnnotationExtension;
223
224 JSON json = JSON.builder()
225 .register(JacksonAnnotationExtension.std)
226 .build();
227 ```
228
229 and then using `JSON` instance as usual.
230
184231 ## Get it!
185232
186233 You can use Maven dependency like:
189236 <dependency>
190237 <groupId>com.fasterxml.jackson.jr</groupId>
191238 <artifactId>jackson-jr-objects</artifactId>
192 <version>2.9.0</version>
239 <version>2.12.0</version>
193240 </dependency>
194241 ```
195242
33 <parent>
44 <groupId>com.fasterxml.jackson.jr</groupId>
55 <artifactId>jackson-jr-parent</artifactId>
6 <version>2.12.0</version>
6 <version>2.12.1</version>
77 </parent>
88 <artifactId>jackson-jr-all</artifactId>
99 <name>jackson-jr-all</name>
55
66 ### Status
77
8 Added in Jackson 2.11 (to be released in Feb/March 2020),
9 considered experimental until following minor version.
8 Added in Jackson 2.11, considered stable as of 2.12 release.
109
1110 ### Usage
1211
77 <parent>
88 <groupId>com.fasterxml.jackson.jr</groupId>
99 <artifactId>jackson-jr-parent</artifactId>
10 <version>2.12.0</version>
10 <version>2.12.1</version>
1111 </parent>
1212 <artifactId>jackson-jr-annotation-support</artifactId>
1313 <packaging>bundle</packaging>
99 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
1010 import com.fasterxml.jackson.annotation.JsonProperty;
1111 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
12
1213 import com.fasterxml.jackson.jr.ob.impl.JSONReader;
1314 import com.fasterxml.jackson.jr.ob.impl.JSONWriter;
1415 import com.fasterxml.jackson.jr.ob.impl.POJODefinition;
219220 }
220221
221222 protected void _findFields() {
222 for (Field f : _type.getDeclaredFields()) {
223 _findFields(_type);
224 }
225
226 protected void _findFields(final Class<?> currType)
227 {
228 if (currType == null || currType == Object.class) {
229 return;
230 }
231 // [jackson-jr#76]: Was not doing recursive field detection
232 // Start with base type fields (so overrides work)
233 _findFields(currType.getSuperclass());
234
235 // then get fields from within class itself
236 for (Field f : currType.getDeclaredFields()) {
223237 // Does not include static fields, but there are couple of things we do
224238 // not include regardless:
225239 if (f.isEnumConstant() || f.isSynthetic()) {
1212 *<ul>
1313 * <li>{link com.fasterxml.jackson.annotation.JsonAlias}: supported on accessors
1414 * (fields, getters, setters)
15 * </li>
16 * <li>{@link com.fasterxml.jackson.annotation.JsonPropertyOrder}: supported on classes
1715 * </li>
1816 * <li>{link com.fasterxml.jackson.annotation.JsonIgnore}: supported on accessors
1917 * (fields, getters, setters)
1717 }
1818 }
1919
20 static class BaseXY {
21 public int x, y;
22
23 protected BaseXY() { }
24 protected BaseXY(int x, int y) {
25 this.x = x;
26 this.y = y;
27 }
28 }
29
2030 @JsonIgnoreProperties({ "y" })
21 static class XYZ {
22 public int x, y, z;
31 static class XYZ
32 extends BaseXY
33 {
34 public int z;
2335
2436 protected XYZ() { }
2537 public XYZ(int x, int y, int z) {
26 this.x = x;
27 this.y = y;
38 super(x, y);
2839 this.z = z;
2940 }
3041 }
3636 // default, no ignorals:
3737 assertEquals(a2q("{'_first':'Bob','_last':'Burger'}"), JSON.std.asString(input));
3838
39 // but if we ignore 'x'...
39 // but if we rename "_last"
4040 assertEquals(a2q("{'_last':'Burger','firstName':'Bob'}"), JSON_WITH_ANNO.asString(input));
4141
4242 // and ensure no leakage to default one:
77 <parent>
88 <groupId>com.fasterxml.jackson.jr</groupId>
99 <artifactId>jackson-jr-parent</artifactId>
10 <version>2.12.0</version>
10 <version>2.12.1</version>
1111 </parent>
1212 <artifactId>jackson-jr-objects</artifactId>
1313 <packaging>bundle</packaging>
77 <parent>
88 <groupId>com.fasterxml.jackson.jr</groupId>
99 <artifactId>jackson-jr-parent</artifactId>
10 <version>2.12.0</version>
10 <version>2.12.1</version>
1111 </parent>
1212 <artifactId>jackson-jr-retrofit2</artifactId>
1313 <packaging>bundle</packaging>
77 <parent>
88 <groupId>com.fasterxml.jackson.jr</groupId>
99 <artifactId>jackson-jr-parent</artifactId>
10 <version>2.12.0</version>
10 <version>2.12.1</version>
1111 </parent>
1212 <artifactId>jackson-jr-stree</artifactId>
1313 <packaging>bundle</packaging>
22 <parent>
33 <groupId>com.fasterxml.jackson</groupId>
44 <artifactId>jackson-base</artifactId>
5 <version>2.12.0</version>
5 <version>2.12.1</version>
66 </parent>
77 <groupId>com.fasterxml.jackson.jr</groupId>
88 <artifactId>jackson-jr-parent</artifactId>
99 <name>Parent pom for Jackson jr components</name>
10 <version>2.12.0</version>
10 <version>2.12.1</version>
1111 <packaging>pom</packaging>
1212 <description>Parent pom for Jackson jr components
1313 </description>
2525 <connection>scm:git:git@github.com:FasterXML/jackson-jr.git</connection>
2626 <developerConnection>scm:git:git@github.com:FasterXML/jackson-jr.git</developerConnection>
2727 <url>http://github.com/FasterXML/jackson-jr</url>
28 <tag>jackson-jr-parent-2.12.0</tag>
28 <tag>jackson-jr-parent-2.12.1</tag>
2929 </scm>
3030
3131 <properties>
33 === Releases ===
44 ------------------------------------------------------------------------
55
6 2.12.1 (08-Jan-2021)
7
8 #76: Annotation-based introspector does not include super-class fields
9
610 2.12.0 (29-Nov-2020)
711
812 - Add Gradle Module Metadata (https://blog.gradle.org/alignment-with-gradle-module-metadata)
913
14 2.11.4 (12-Dec-2020)
1015 2.11.3 (02-Oct-2020)
1116
1217 No changes since 2.11.2