{"id":19563111,"url":"https://github.com/fasterxml/jackson-jr","last_synced_at":"2025-05-14T04:10:14.540Z","repository":{"id":45086327,"uuid":"12667858","full_name":"FasterXML/jackson-jr","owner":"FasterXML","description":"Stand-alone data-binding module designed as a light-weight (and -featured) alternative to `jackson-databind`: will only deal with \"Maps, Lists, Strings, wrappers and Java Beans\" (jr-objects), or simple read-only trees (jr-stree)","archived":false,"fork":false,"pushed_at":"2025-05-10T23:36:16.000Z","size":5382,"stargazers_count":249,"open_issues_count":9,"forks_count":34,"subscribers_count":11,"default_branch":"2.x","last_synced_at":"2025-05-11T00:19:33.401Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FasterXML.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-09-07T16:34:33.000Z","updated_at":"2025-05-09T02:32:36.000Z","dependencies_parsed_at":"2023-10-11T00:42:32.051Z","dependency_job_id":"b8cd76c9-e52a-471e-88aa-eaad82bcf0cd","html_url":"https://github.com/FasterXML/jackson-jr","commit_stats":{"total_commits":970,"total_committers":17,"mean_commits":57.05882352941177,"dds":0.07938144329896912,"last_synced_commit":"859e2f9064e745811f4653c9e91c28f6ea8eeeaf"},"previous_names":[],"tags_count":141,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FasterXML%2Fjackson-jr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FasterXML%2Fjackson-jr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FasterXML%2Fjackson-jr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FasterXML%2Fjackson-jr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FasterXML","download_url":"https://codeload.github.com/FasterXML/jackson-jr/tar.gz/refs/heads/2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254070111,"owners_count":22009559,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T05:16:35.891Z","updated_at":"2025-05-14T04:10:09.484Z","avatar_url":"https://github.com/FasterXML.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Overview\n\nJackson jr is a compact alternative to full [Jackson Databind](../../../jackson-databind) component.\nIt implements a subset of functionality, for example for cases where:\n\n1. Size of jar matters (`jackson-jr-objects` is bit over 100 kB)\n2. Startup time matters (`jackson-jr` has very low initialization overhead)\n\nIn addition to basic datatypes (core JDK types like `List`s, `Map`s, wrapper types),\npackage supports reading and writing of standard Java Beans (implementation that mimics standard\nJDK Bean Introspection): that is,\nsubset of POJOs that define setters/getters and/or `public` fields.\nAnd starting with 2.11 there is even optional support for a subset of Jackson annotations\nvia optional `jackson-jr-annotation-support` extension.\n\nJackson-jr also adds  `composer` implementation that can be used to\nconstruct JSON output with builder-style API, but without necessarily having\nto build an in-memory representation: instead, it can directly use `streaming-api`\nfor direct output. It is also possible to build actual in-memory\nJSON `String` or `byte[]` representation, if that is preferable.\n\nMain Jackson-jr artifact (`jackson-jr-objects`) itself is currently about 120 kB in size, and only depends on\n[Jackson Streaming API](../../../jackson-core) package.\nCombined size, for \"all\" jar, is bit over 500 kB (of which streaming API is about 350 kB),\nfor use cases where a single jar is preferred over more modular approach.\nFinally, use of jar minimizers like [ProGuard](https://proguard.sourceforge.net/) can bring the jar\nsize down even further, by renaming and removing debug information.\n\n## License\n\nGood old [Apache License](https://www.apache.org/licenses/LICENSE-2.0).\n\n## Packaging\n\nProject is composed of multiple Maven sub-modules, each corresponding to a jar:\n\n* [jr-objects](../../tree/master/jr-objects) contains the \"core\" databinding implementation, and is commonly the only dependency to use\n    * Depends on `jackson-core` for low-level reading/writing\n* [jr-stree](../../tree/master/jr-stree) contains a simple `TreeCodec` implementation, with which it is possible to read JSON as `TreeNode`s (see more below)\n* [jr-retrofit2](../../tree/master/jr-retrofit2) contains `jackson-jr` - based handlers for [Retrofit 2](https://square.github.io/retrofit/) library\n    * Depends on `jackson-jr` and `Retrofit` API jars, and indirectly on `jackson-core`\n* [jr-annotation-support](../../tree/master/jr-annotation-support) contains extension with support for a subset of core [Jackson annotations](../../../jackson-annotations)\n* [jr-extension-javatime](../../tree/master/jr-extension-javatime) contains extension with support for a subset of Java 8 Date/Time types (e.g. `java.time.LocalDateTime`)\n* jr-all creates an \"uber-jar\" that contains individual modules along with all their dependencies:\n    * `jr-objects` classes as-is, without relocating\n    * `jr-stree` classes as-is, without relocating\n    * Jackson streaming (`jackson-core`) contents *relocated* (\"shaded\"), for private use by `jackson-jr`\n    * Does NOT contain `jr-retrofit2` or `jr-annotation-support` components\n\nIf you are not sure which package to use, the answer is usually `jr-objects`, and build system (maven, gradle) will fetch the dependency needed. `jr-all` jar is only used if the single-jar deployment (self-contained, no external dependencies) is needed.\n\n## Status\n\n[![Build Status](https://travis-ci.org/FasterXML/jackson-jr.svg)](https://travis-ci.org/FasterXML/jackson-jr)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.fasterxml.jackson.jr/jackson-jr-objects/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.fasterxml.jackson.jr/jackson-jr-objects/)\n[![Javadoc](https://javadoc.io/badge/com.fasterxml.jackson.jr/jackson-jr-objects.svg)](https://www.javadoc.io/doc/com.fasterxml.jackson.jr/jackson-jr-objects)\n\n## Usage\n\n### Reading/writing Simple Objects, Beans, List/arrays thereof\n\nFunctionality of this package is contained in Java package `com.fasterxml.jackson.jr.ob`.\n\nAll functionality is accessed through main `JSON` Object; you can either used singleton `JSON.std`,\nor construct individual objects -- either way, `JSON` instances are ALWAYS immutable and hence thread-safe.\n\nWe can start by reading JSON\n\n```java\nString INPUT = \"{\\\"a\\\":[1,2,{\\\"b\\\":true},3],\\\"c\\\":3}\";\nObject ob = JSON.std.anyFrom(INPUT);\n// or\nMap\u003cString,Object\u003e map = JSON.std.mapFrom(INPUT);\n// or\nMyBean bean = JSON.std.beanFrom(MyBean.class, INPUT);\n```\n\nfrom any of the usual input sources (`InputStream`, `Reader`, `String` or `byte[]` that contains JSON, `URL`,\n`JsonParser`); and can write same Objects as JSON:\n\n```java\nString json = JSON.std.asString(map);\nJSON.std.write(ob, new File(\"/tmp/stuff.json\");\n// and with indentation; but skip writing of null properties\nbyte[] bytes = JSON.std\n    .with(Feature.PRETTY_PRINT_OUTPUT)\n    .without(Feature.WRITE_NULL_PROPERTIES)\n    .asBytes(bean);\n```\n\nand may also read `List`s and arrays of simple and Bean types:\n\n```java\nList\u003cMyType\u003e beans = JSON.std.listOfFrom(MyType.class, INPUT);\n```\n\n(writing of `List`s and arrays works without addition effort: just pass List/array as-is)\n\n### Reading \"streaming JSON\" (LD-JSON)\n\nVersion 2.10 added ability to read [Streaming JSON](https://en.wikipedia.org/wiki/JSON_streaming) content.\nSee [\"Jackson 2.10 features\"](https://medium.com/@cowtowncoder/jackson-2-10-features-cd880674d8a2) (section \"Jackson-jr feature expansion\") for full example, but basic\nreading is done using new `ValueIterator` abstraction: \n\n```\nFile input = new File(\"json-stream.ldjson\");\ntry (ValueIterator\u003cBean\u003e it = JSON.std.beanSequenceFrom(Bean.class, input)) {\n  while ((Bean bean = it.nextValue()) != null) {\n    // do something with 'bean'\n  }\n}\n```\n\n### Writing with composers\n\nAn alternative method exists for writing: \"fluent\" style output can be used as follows:\n\n```java\nString json = JSON.std\n  .with(JSON.Feature.PRETTY_PRINT_OUTPUT)\n  .composeString()\n  .startObject()\n    .put(\"a\", 1)\n    .startArrayField(\"arr\")\n      .add(1).add(2).add(3)\n    .end()\n    .startObjectField(\"ob\")\n      .put(\"x\", 3)\n      .put(\"y\", 4)\n      .startArrayField(\"args\").add(\"none\").end()\n    .end()\n    .put(\"last\", true)\n  .end()\n  .finish();\n```\n\nwould produce (since pretty-printing is enabled)\n\n```json\n{\n  \"a\" : 1,\n  \"arr\" : [1,2,3],\n  \"ob\" : {\n    \"x\" : 3,\n    \"y\" : 4,\n    \"args\" : [\"none\"]\n  },\n  \"last\" : true\n}\n```\n\n### Reading/writing JSON Trees\n\nJackson jr allows pluggable \"tree models\", and also provides one implementation, `jr-stree`.\nUsage for `jr-stree` is by configuring `JSON` with codec, and then using `treeFrom` and `write` methods\nlike so:\n\n```java\nJSON json = JSON.std.with(new JacksonJrsTreeCodec());\nTreeNode root = json.treeFrom(\"{\\\"value\\\" : [1, 2, 3]}\");\nassertTrue(root.isObject());\nTreeNode array = root.get(\"value\");\nassertTrue(array.isArray());\nJrsNumber n = (JrsNumber) array.get(1);\nassertEquals(2, n.getValue().intValue());\n\nString json = json.asString(root);\n```\n\nNote that `jr-stree` implementation is a small minimalistic implementation with immutable\nnodes. It is most useful for simple reading use cases.\n\nIt is however possible to write your own `TreeCodec` implementations that integrate seamlessly,\nand in future other tree models may be offered as part of jackson-jr, or via other libraries.\n\n### Designing your Beans\n\nTo support readability and writability of your own types, your Java objects must either:\n\n* 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\n* Define single-argument constructor if binding from JSON String (single-String argument) or JSON integer number (single-`long` or `Long` argument)\n\nNote that although getters and setters need to be public (since JDK Bean Introspection does not find any other methods),\nconstructors may have any access right, including `private`.\n\nStarting with version 2.8, `public` fields may also be used (although their\ndiscovery may be disabled using `JSON.Feature.USE_FIELDS`) as an alternative:\nthis is useful when limiting number of otherwise useless \"getter\" and \"setter\"\nmethods.\n\nNEW! Jackson-jr 2.11 introduce `jackson-jr-annotation-support` extension (see more below)\nwhich allows use of Jackson annotations like `@JsonProperty`, `@JsonIgnore` and even `@JsonAutoDetect` for even more granular control of inclusion, naming and renaming.\n\n### Customizing behavior with Features\n\nThere are many customizable features you can use with `JSON` object; see [Full List of Features](../../wiki/JSON-Features) for details. But usage itself is via fluent methods like so:\n\n```java\nString json = JSON.std\n  .with(JSON.Feature.PRETTY_PRINT_OUTPUT)\n  .without(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS)\n  .asString(...);\n```\n\n### Adding custom value readers, writers\n\nVersion 2.10 added ability to add custom `ValueReader`s and `ValueWriter`s, to\nallow pluggable support for types beyond basic JDK types and Beans.\n\nSee 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\n\nYou can also check out unit test\n\n    jr-objects/src/test/java/com/fasterxml/jackson/jr/ob/impl/CustomValueReadersTest.java\n\nfor sample usage.\n\nThere is also a blog post [Enable support for java.time.* with Jackson-jr](https://www.andersaaberg.dk/2020/enable-support-for-java-time-with-jackson-jr/) which shows how to write custom readers/writers; in this\ncase ones for Java 8 date/time types, but the concept is general.\n\n### Using (some of) Jackson annotations\n\nJackson 2.11 added a new extension (a `JacksonJrExtension`) -- `jr-annotation-support` -- that adds support for a subset of Jackson annotations.\nSee [jr-annotation-support/README.md](../../tree/master/jr-annotation-support) for details of this extension, but basic usage is by registering extension:\n\n```\nimport com.fasterxml.jackson.jr.annotationsupport.JacksonAnnotationExtension;\n\nJSON json = JSON.builder()\n    .register(JacksonAnnotationExtension.std)\n    .build();\n```\n\nand then using `JSON` instance as usual.\n\n## Get it!\n\nYou can use Maven dependency like:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.fasterxml.jackson.jr\u003c/groupId\u003e\n  \u003cartifactId\u003ejackson-jr-objects\u003c/artifactId\u003e\n  \u003cversion\u003e2.18.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nand then you can also download jars via [Central Maven repository](https://repo1.maven.org/maven2/com/fasterxml/jackson/jr/jackson-jr-objects/).\n\nOr you can also clone the project and build it locally with `mvn clean install`.\n\nAlternatively if you want a single jar deployment, you can use `jackson-jr-all` jar which embeds `jackson-core`\n(repackaged using Shade plug-in, so as not to conflict with \"vanilla\" `jackson-core`):\n\n    https://repo1.maven.org/maven2/com/fasterxml/jackson/jr/jackson-jr-all/\n\n## Performance\n\nInitial performance testing using [JVM Serializers](https://github.com/eishay/jvm-serializers/wiki) benchmark\nsuggests that it is almost as fast as [full Jackson databind](https://github.com/FasterXML/jackson-databind) --\nadditional overhead for tests is 5-10% for both serialization and deserialization.\nSo performance is practically identical.\n\nIn fact, when only handling `List`s and `Map`s style content, speed `jackson-jr` speed fully matches `jackson-databind`\nperformance (Bean/POJO case is where full databinding's extensive optimizations help more).\nSo performance should be adequate, and choice should be more based on functionality, convenience and\ndeployment factors.\n\nAbout the only thing missing is that there is no equivalent to [Afterburner](../../../jackson-module-afterburner), which\ncan further speed up databind by 20-30%, for most performance-sensitive systems.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffasterxml%2Fjackson-jr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffasterxml%2Fjackson-jr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffasterxml%2Fjackson-jr/lists"}