{"id":15028521,"url":"https://github.com/fasterxml/jackson-databind","last_synced_at":"2025-11-12T21:33:46.094Z","repository":{"id":2098093,"uuid":"3038937","full_name":"FasterXML/jackson-databind","owner":"FasterXML","description":"General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)","archived":false,"fork":false,"pushed_at":"2025-09-03T03:44:24.000Z","size":83028,"stargazers_count":3614,"open_issues_count":384,"forks_count":1438,"subscribers_count":168,"default_branch":"2.x","last_synced_at":"2025-09-04T09:46:13.395Z","etag":null,"topics":["hacktoberfest","jackson","jackson-databind","json"],"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":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"tidelift":"maven/com.fasterxml.jackson.core:jackson-databind","github":"cowtowncoder"}},"created_at":"2011-12-23T07:17:41.000Z","updated_at":"2025-09-04T07:24:56.000Z","dependencies_parsed_at":"2024-05-29T03:58:02.675Z","dependency_job_id":"3774e870-3005-4977-b5e0-cbc50c6a4d09","html_url":"https://github.com/FasterXML/jackson-databind","commit_stats":{"total_commits":6633,"total_committers":286,"mean_commits":"23.192307692307693","dds":0.148047640584954,"last_synced_commit":"bb5b3cc63a5a5594e3fe0d4fd105acffaa09b30a"},"previous_names":[],"tags_count":219,"template":false,"template_full_name":null,"purl":"pkg:github/FasterXML/jackson-databind","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FasterXML%2Fjackson-databind","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FasterXML%2Fjackson-databind/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FasterXML%2Fjackson-databind/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FasterXML%2Fjackson-databind/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FasterXML","download_url":"https://codeload.github.com/FasterXML/jackson-databind/tar.gz/refs/heads/2.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FasterXML%2Fjackson-databind/sbom","scorecard":{"id":49363,"data":{"date":"2025-08-11","repo":{"name":"github.com/FasterXML/jackson-databind","commit":"abe7a7803535b6adf387ee0e78d6a3c8660d416a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":7.9,"checks":[{"name":"Code-Review","score":0,"reason":"Found 1/29 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":10,"reason":"30 commit(s) and 25 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: SECURITY.md:1","Info: Found linked content: SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1","Info: Found text in security policy: SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Token-Permissions","score":10,"reason":"GitHub workflow tokens follow principle of least privilege","details":["Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:15","Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:16","Info: topLevel 'contents' permission set to 'read': .github/workflows/cifuzz.yml:8","Info: topLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:8","Info: topLevel 'contents' permission set to 'read': .github/workflows/dep_build_v2.yml:9","Info: topLevel 'contents' permission set to 'read': .github/workflows/dep_build_v3.yml:9","Info: topLevel 'contents' permission set to 'read': .github/workflows/main.yml:13","Info: topLevel 'contents' permission set to 'read': .github/workflows/trigger_dep_builds_v2.yml:8","Info: topLevel 'contents' permission set to 'read': .github/workflows/trigger_dep_builds_v3.yml:8","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":7,"reason":"dependency not pinned by hash detected -- score normalized to 7","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/cifuzz.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/FasterXML/jackson-databind/cifuzz.yml/2.x?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/cifuzz.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/FasterXML/jackson-databind/cifuzz.yml/2.x?enable=pin","Info:  11 out of  11 GitHub-owned GitHubAction dependencies pinned","Info:   3 out of   5 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":10,"reason":"project is fuzzed","details":["Info: OSSFuzz integration found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":3,"reason":"branch protection is not maximal on development and all release branches","details":["Info: 'allow deletion' disabled on branch '2.x'","Info: 'force pushes' disabled on branch '2.x'","Warn: branch '2.x' does not require approvers","Warn: codeowners review is not required on branch '2.x'","Warn: no status checks found to merge onto branch '2.x'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Packaging","score":10,"reason":"packaging workflow detected","details":["Info: Project packages its releases by way of GitHub Actions.: .github/workflows/main.yml:16"],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":7,"reason":"SAST tool detected but not run on all commits","details":["Info: SAST configuration detected: CodeQL","Warn: 0 commits out of 5 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-14T23:24:41.015Z","repository_id":2098093,"created_at":"2025-08-14T23:24:41.015Z","updated_at":"2025-08-14T23:24:41.015Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274358726,"owners_count":25270680,"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","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["hacktoberfest","jackson","jackson-databind","json"],"created_at":"2024-09-24T20:08:32.331Z","updated_at":"2025-11-12T21:33:46.038Z","avatar_url":"https://github.com/FasterXML.png","language":"Java","funding_links":["https://tidelift.com/funding/github/maven/com.fasterxml.jackson.core:jackson-databind","https://github.com/sponsors/cowtowncoder","https://tidelift.com/badges/package/maven/com.fasterxml.jackson.core:jackson-databind","https://tidelift.com/subscription/pkg/maven-com-fasterxml-jackson-core-jackson-databind?utm_source=maven-com-fasterxml-jackson-core-jackson-databind\u0026utm_medium=referral\u0026utm_campaign=readme","https://tidelift.com/subscription/pkg/maven-com-fasterxml-jackson-core-jackson-databind","https://tidelift.com/subscription/pkg/maven-com-fasterxml-jackson-core-jackson-databind?utm_source=maven-com-fasterxml-jackson-core-jackson-databind\u0026utm_medium=referral\u0026utm_campaign=enterprise\u0026utm_term=repo"],"categories":[],"sub_categories":[],"readme":"# Overview\n\nThis project contains the general-purpose data-binding functionality\nand tree-model for [Jackson Data Processor](../../../jackson).\nIt builds on [Streaming API](../../../jackson-core) (stream parser/generator) package,\nand uses [Jackson Annotations](../../../jackson-annotations) for configuration.\nProject is licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).\n\nWhile the original use case for Jackson was JSON data-binding, it can now be used to read content\nencoded in other data formats as well, as long as parser and generator implementations exist.\nNaming of classes uses word 'JSON' in many places even though there is no actual hard dependency to JSON format.\n\n## Status\n\n| Type | Status |\n| ---- | ------ |\n| Build (CI) | [![Build (github)](https://github.com/FasterXML/jackson-databind/actions/workflows/main.yml/badge.svg)](https://github.com/FasterXML/jackson-databind/actions/workflows/main.yml) |\n| Artifact | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.fasterxml.jackson.core/jackson-databind/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.fasterxml.jackson.core/jackson-databind) |\n| OSS Sponsorship | [![Tidelift](https://tidelift.com/badges/package/maven/com.fasterxml.jackson.core:jackson-databind)](https://tidelift.com/subscription/pkg/maven-com-fasterxml-jackson-core-jackson-databind?utm_source=maven-com-fasterxml-jackson-core-jackson-databind\u0026utm_medium=referral\u0026utm_campaign=readme) |\n| Javadocs | [![Javadoc](https://javadoc.io/badge/com.fasterxml.jackson.core/jackson-databind.svg)](http://www.javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind) |\n| Code coverage (2.19) | [![codecov.io](https://codecov.io/github/FasterXML/jackson-databind/coverage.svg?branch=2.19)](https://codecov.io/github/FasterXML/jackson-databind?branch=2.19) |\n| OpenSSF Score | [![OpenSSF  Scorecard](https://api.securityscorecards.dev/projects/github.com/FasterXML/jackson-databind/badge)](https://securityscorecards.dev/viewer/?uri=github.com/FasterXML/jackson-databind) |\n\n# Get it!\n\n## Maven\n\nFunctionality of this package is contained in Java package `com.fasterxml.jackson.databind`, and can be used using following Maven dependency:\n\n```xml\n\u003cproperties\u003e\n  ...\n  \u003c!-- Use the latest version whenever possible. --\u003e\n  \u003cjackson.version\u003e2.19.0\u003c/jackson.version\u003e\n  ...\n\u003c/properties\u003e\n\n\u003cdependencies\u003e\n  ...\n  \u003cdependency\u003e\n    \u003cgroupId\u003ecom.fasterxml.jackson.core\u003c/groupId\u003e\n    \u003cartifactId\u003ejackson-databind\u003c/artifactId\u003e\n    \u003cversion\u003e${jackson.version}\u003c/version\u003e\n  \u003c/dependency\u003e\n  ...\n\u003c/dependencies\u003e\n```\n\nPackage also depends on `jackson-core` and `jackson-annotations` packages, but when using build tools\nlike Maven or Gradle, dependencies are automatically included.\nYou may, however, want to use [jackson-bom](../../../jackson-bom) to ensure compatible versions\nof dependencies.\nIf not using build tool that can handle dependencies using project's `pom.xml`, you will need to download\nand include these 2 jars explicitly.\n\n## Non-Maven dependency resolution\n\nFor use cases that do not automatically resolve dependencies from Maven repositories, you can still\ndownload jars from [Central Maven repository](https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/).\n\nDatabind jar is also a functional OSGi bundle, with proper import/export declarations, so it can be use on OSGi container as is.\n\nJackson 2.10 and above include `module-info.class` definitions so the jar is also a proper Java Module (JPMS).\n\nJackson 2.12 and above include additional Gradle 6 Module Metadata for version alignment with Gradle.\n\n-----\n## Compatibility\n\n### JDK\n\nJackson-databind package baseline JDK requirements are as follows:\n\n* Versions 2.0 - 2.7 require JDK 6\n* Versions 2.8 - 2.12 require JDK 7 to run (but 2.11 - 2.12 require JDK 8 to build)\n* Versions 2.13 and above require JDK 8\n\n### Android\n\nList is incomplete due to compatibility checker addition being done for Jackson 2.13.\n\n* 2.13: Android SDK 24+\n* 2.14: Android SDK 26+\n* 2.15: Android SDK 26+\n* 2.16: Android SDK 26+\n* 2.17: Android SDK 26+\n* 2.18: (planned) Android SDK 26+\n\nfor information on Android SDK versions to Android Release names see [https://en.wikipedia.org/wiki/Android_version_history]\n\n-----\n\n# Use It!\n\nMore comprehensive documentation can be found from [Jackson-docs](../../../jackson-docs) repository; as well as from [Wiki](../../wiki) of this project.\nBut here are brief introductionary tutorials, in recommended order of reading.\n\n## 1 minute tutorial: POJOs to JSON and back\n\nThe most common usage is to take piece of JSON, and construct a Plain Old Java Object (\"POJO\") out of it. So let's start there. With simple 2-property POJO like this:\n\n```java\n// Note: can use getters/setters as well; here we just use public fields directly:\npublic class MyValue {\n  public String name;\n  public int age;\n  // NOTE: if using getters/setters, can keep fields `protected` or `private`\n}\n```\n\nwe will need a `com.fasterxml.jackson.databind.ObjectMapper` instance, used for all data-binding, so let's construct one:\n\n```java\nObjectMapper mapper = new ObjectMapper(); // create once, reuse\n```\n\nThe default instance is fine for our use -- we will learn later on how to configure mapper instance if necessary. Usage is simple:\n\n```java\nMyValue value = mapper.readValue(new File(\"data.json\"), MyValue.class);\n// or:\nvalue = mapper.readValue(new URL(\"http://some.com/api/entry.json\"), MyValue.class);\n// or:\nvalue = mapper.readValue(\"{\\\"name\\\":\\\"Bob\\\", \\\"age\\\":13}\", MyValue.class);\n```\n\nAnd if we want to write JSON, we do the reverse:\n\n```java\nmapper.writeValue(new File(\"result.json\"), myResultObject);\n// or:\nbyte[] jsonBytes = mapper.writeValueAsBytes(myResultObject);\n// or:\nString jsonString = mapper.writeValueAsString(myResultObject);\n```\n\nSo far so good?\n\n## 3 minute tutorial: Generic collections, Tree Model\n\nBeyond dealing with simple Bean-style POJOs, you can also handle JDK `List`s, `Map`s:\n\n```java\nMap\u003cString, Integer\u003e scoreByName = mapper.readValue(jsonSource, Map.class);\nList\u003cString\u003e names = mapper.readValue(jsonSource, List.class);\n\n// and can obviously write out as well\nmapper.writeValue(new File(\"names.json\"), names);\n```\n\nas long as JSON structure matches, and types are simple.\nIf you have POJO values, you need to indicate actual type (note: this is NOT needed for POJO properties with `List` etc types):\n\n```java\nMap\u003cString, ResultValue\u003e results = mapper.readValue(jsonSource,\n   new TypeReference\u003cMap\u003cString, ResultValue\u003e\u003e() { } );\n// why extra work? Java Type Erasure will prevent type detection otherwise\n```\n\n(note: no extra effort needed for serialization, regardless of generic types)\n\nBut wait! There is more!\n\n(enters Tree Model...)\n\n### Tree Model\n\nWhile dealing with `Map`s, `List`s and other \"simple\" Object types (Strings, Numbers, Booleans) can be simple, Object traversal can be cumbersome.\nThis is where Jackson's [Tree model](https://github.com/FasterXML/jackson-databind/wiki/JacksonTreeModel) can come in handy:\n\n```java\n// can be read as generic JsonNode, if it can be Object or Array; or,\n// if known to be Object, as ObjectNode, if array, ArrayNode etc:\nJsonNode root = mapper.readTree(\"{ \\\"name\\\": \\\"Joe\\\", \\\"age\\\": 13 }\");\nString name = root.get(\"name\").asText();\nint age = root.get(\"age\").asInt();\n\n// can modify as well: this adds child Object as property 'other', set property 'type'\nroot.withObject(\"/other\").put(\"type\", \"student\");\nString json = mapper.writeValueAsString(root); // prints below\n\n/*\nwith above, we end up with something like as 'json' String:\n{\n  \"name\" : \"Bob\",\n  \"age\" : 13,\n  \"other\" : {\n    \"type\" : \"student\"\n  }\n} \n*/\n```\n\nTree Model can be more convenient than data-binding, especially in cases where structure is highly dynamic, or does not map nicely to Java classes.\n\nFinally, feel free to mix and match, and even in the same json document (useful when only part of the document is known and modeled in your code)\n\n```java\n// Some parts of this json are modeled in our code, some are not\nJsonNode root = mapper.readTree(complexJson);\nPerson p = mapper.treeToValue(root.get(\"person\"), Person.class); // known single pojo\nMap\u003cString, Object\u003e dynamicmetadata = mapper.treeToValue(root.get(\"dynamicmetadata\"), Map.class); // unknown smallish subfield, convert all to collections\nint singledeep = root.get(\"deep\").get(\"large\").get(\"hiearchy\").get(\"important\").intValue(); // single value in very deep optional subfield, ignoring the rest\nint singledeeppath = root.at(\"/deep/large/hiearchy/important\").intValue(); // json path\nint singledeeppathunique = root.findValue(\"important\").intValue(); // by unique field name\n\n// Send an aggregate json from heterogenous sources\nObjectNode root = mapper.createObjectNode();\nroot.putPOJO(\"person\", new Person(\"Joe\")); // simple pojo\nroot.putPOJO(\"friends\", List.of(new Person(\"Jane\"), new Person(\"Jack\"))); // generics\nMap\u003cString, Object\u003e dynamicmetadata = Map.of(\"Some\", \"Metadata\");\nroot.putPOJO(\"dynamicmetadata\", dynamicmetadata);  // collections\nroot.putPOJO(\"dynamicmetadata\", mapper.valueToTree(dynamicmetadata)); // same thing\nroot.set(\"dynamicmetadata\", mapper.valueToTree(dynamicmetadata)); // same thing\nroot.withObject(\"deep\").withObject(\"large\").withObject(\"hiearchy\").put(\"important\", 42); // create as you go\nroot.withObject(\"/deep/large/hiearchy\").put(\"important\", 42); // json path\nmapper.writeValueAsString(root);\n```\n\n**Supported for Jackson 2.16+ versions**\n\n```java\n// generics\nList\u003cPerson\u003e friends = mapper.treeToValue(root.get(\"friends\"), new TypeReference\u003cList\u003cPerson\u003e\u003e() { });\n// create as you go but without trying json path\nroot.withObjectProperty(\"deep\").withObjectProperty(\"large\").withObjectProperty(\"hiearchy\").put(\"important\", 42);\n```\n\n## 5 minute tutorial: Streaming parser, generator\n\nAs convenient as data-binding (to/from POJOs) can be; and as flexible as Tree model can be, there is one more canonical processing model available: incremental (aka \"streaming\") model.\nIt is the underlying processing model that data-binding and Tree Model both build upon, but it is also exposed to users who want ultimate performance and/or control over parsing or generation details.\n\nFor in-depth explanation, look at [Jackson Core component](https://github.com/FasterXML/jackson-core).\nBut let's look at a simple teaser to whet your appetite.\n\n```java\nObjectMapper mapper = ...;\n// First: write simple JSON output\nFile jsonFile = new File(\"test.json\");\n// note: method added in Jackson 2.11 (earlier would need to use\n// mapper.getFactory().createGenerator(...)\nJsonGenerator g = mapper.createGenerator(jsonFile, JsonEncoding.UTF8);\n// write JSON: { \"message\" : \"Hello world!\" }\ng.writeStartObject();\ng.writeStringField(\"message\", \"Hello world!\");\ng.writeEndObject();\ng.close();\n\n// Second: read file back\ntry (JsonParser p = mapper.createParser(jsonFile)) {\n  JsonToken t = p.nextToken(); // Should be JsonToken.START_OBJECT\n  t = p.nextToken(); // JsonToken.FIELD_NAME\n  if ((t != JsonToken.FIELD_NAME) || !\"message\".equals(p.getCurrentName())) {\n   // handle error\n  }\n  t = p.nextToken();\n  if (t != JsonToken.VALUE_STRING) {\n   // similarly\n  }\n  String msg = p.getText();\n  System.out.printf(\"My message to you is: %s!\\n\", msg);\n}\n```\n\n## 10 minute tutorial: configuration\n\nThere are two entry-level configuration mechanisms you are likely to use:\n[Features](https://github.com/FasterXML/jackson-databind/wiki/JacksonFeatures) and [Annotations](https://github.com/FasterXML/jackson-annotations).\n\n### Commonly used Features\n\nHere are examples of configuration features that you are most likely to need to know about.\n\nLet's start with higher-level data-binding configuration.\n\n```java\n// SerializationFeature for changing how JSON is written\n\n// to enable standard indentation (\"pretty-printing\"):\nmapper.enable(SerializationFeature.INDENT_OUTPUT);\n// to allow serialization of \"empty\" POJOs (no properties to serialize)\n// (without this setting, an exception is thrown in those cases)\nmapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);\n// to write java.util.Date, Calendar as number (timestamp):\nmapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);\n\n// DeserializationFeature for changing how JSON is read as POJOs:\n\n// to prevent exception when encountering unknown property:\nmapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);\n// to allow coercion of JSON empty String (\"\") to null Object value:\nmapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);\n```\n\nIn addition, you may need to change some of low-level JSON parsing, generation details:\n\n```java\n// JsonParser.Feature for configuring parsing settings:\n\n// to allow C/C++ style comments in JSON (non-standard, disabled by default)\n// (note: with Jackson 2.5, there is also `mapper.enable(feature)` / `mapper.disable(feature)`)\nmapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);\n// to allow (non-standard) unquoted field names in JSON:\nmapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);\n// to allow use of apostrophes (single quotes), non standard\nmapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);\n\n// JsonGenerator.Feature for configuring low-level JSON generation:\n\n// to force escaping of non-ASCII characters:\nmapper.configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);\n```\n\nFull set of features are explained on [Jackson Features](https://github.com/FasterXML/jackson-databind/wiki/JacksonFeatures) page.\n\n### Annotations: changing property names\n\nThe simplest annotation-based approach is to use `@JsonProperty` annotation like so:\n\n```java\npublic class MyBean {\n   private String _name;\n\n   // without annotation, we'd get \"theName\", but we want \"name\":\n   @JsonProperty(\"name\")\n   public String getTheName() { return _name; }\n\n   // note: it is enough to add annotation on just getter OR setter;\n   // so we can omit it here\n   public void setTheName(String n) { _name = n; }\n}\n```\n\nThere are other mechanisms to use for systematic naming changes, including use of \"Naming Strategy\" (via `@JsonNaming` annotation).\n\nYou can use [Mix-in Annotations](https://github.com/FasterXML/jackson-docs/wiki/JacksonMixinAnnotations) to associate any and all Jackson-provided annotations.\n\n### Annotations: Ignoring properties\n\nThere are two main annotations that can be used to ignore properties: `@JsonIgnore` for individual properties; and `@JsonIgnoreProperties` for per-class definition\n\n```java\n// means that if we see \"foo\" or \"bar\" in JSON, they will be quietly skipped\n// regardless of whether POJO has such properties\n@JsonIgnoreProperties({ \"foo\", \"bar\" })\npublic class MyBean\n{\n   // will not be written as JSON; nor assigned from JSON:\n   @JsonIgnore\n   public String internal;\n\n   // no annotation, public field is read/written normally\n   public String external;\n\n   @JsonIgnore\n   public void setCode(int c) { _code = c; }\n\n   // note: will also be ignored because setter has annotation!\n   public int getCode() { return _code; }\n}\n```\n\nAs with renaming, note that annotations are \"shared\" between matching fields, getters and setters: if only one has `@JsonIgnore`, it affects others.\nBut it is also possible to use \"split\" annotations, to for example:\n\n```java\npublic class ReadButDontWriteProps {\n   private String _name;\n   @JsonProperty public void setName(String n) { _name = n; }\n   @JsonIgnore public String getName() { return _name; }\n}\n```\n\nin this case, no \"name\" property would be written out (since 'getter' is ignored); but if \"name\" property was found from JSON, it would be assigned to POJO property!\n\nFor a more complete explanation of all possible ways of ignoring properties when writing out JSON, check [\"Filtering properties\"](http://www.cowtowncoder.com/blog/archives/2011/02/entry_443.html) article.\n\n### Annotations: using custom constructor\n\nUnlike many other data-binding packages, Jackson does not require you to define \"default constructor\" (constructor that does not take arguments).\nWhile it will use one if nothing else is available, you can easily define that an argument-taking constructor is used:\n\n```java\npublic class CtorBean\n{\n  public final String name;\n  public final int age;\n\n  @JsonCreator // constructor can be public, private, whatever\n  private CtorBean(@JsonProperty(\"name\") String name,\n    @JsonProperty(\"age\") int age)\n  {\n      this.name = name;\n      this.age = age;\n  }\n}\n```\n\nConstructors are especially useful in supporting use of\n[Immutable objects](http://www.cowtowncoder.com/blog/archives/2010/08/entry_409.html).\n\nAlternatively, you can also define \"factory methods\":\n\n```java\npublic class FactoryBean\n{\n    // fields etc omitted for brevity\n\n    @JsonCreator\n    public static FactoryBean create(@JsonProperty(\"name\") String name) {\n      // construct and return an instance\n    }\n}\n```\n\nNote that use of a \"creator method\" (`@JsonCreator` with `@JsonProperty` annotated arguments) does not preclude use of setters: you\ncan mix and match properties from constructor/factory method with ones that\nare set via setters or directly using fields.\n\n## Tutorial: fancier stuff, conversions\n\nOne useful (but not very widely known) feature of Jackson is its ability\nto do arbitrary POJO-to-POJO conversions. Conceptually you can think of conversions as sequence of 2 steps: first, writing a POJO as JSON, and second, binding that JSON into another kind of POJO. Implementation just skips actual generation of JSON, and uses more efficient intermediate representation.\n\nConversions work between any compatible types, and invocation is as simple as:\n\n```java\nResultType result = mapper.convertValue(sourceObject, ResultType.class);\n```\n\nand as long as source and result types are compatible -- that is, if to-JSON, from-JSON sequence would succeed -- things will \"just work\".\nBut here are a couple of potentially useful use cases:\n\n```java\n// Convert from List\u003cInteger\u003e to int[]\nList\u003cInteger\u003e sourceList = ...;\nint[] ints = mapper.convertValue(sourceList, int[].class);\n// Convert a POJO into Map!\nMap\u003cString,Object\u003e propertyMap = mapper.convertValue(pojoValue, Map.class);\n// ... and back\nPojoType pojo = mapper.convertValue(propertyMap, PojoType.class);\n// decode Base64! (default byte[] representation is base64-encoded String)\nString base64 = \"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\";\nbyte[] binary = mapper.convertValue(base64, byte[].class);\n```\n\nBasically, Jackson can work as a replacement for many Apache Commons components, for tasks like base64 encoding/decoding, and handling of \"dyna beans\" (Maps to/from POJOs).\n\n## Tutorial: Builder design pattern + Jackson\nThe Builder design pattern is a creational design pattern and can be used to create complex objects step by step.\nIf we have an object that needs multiple checks on other dependencies, In such cases, it is preferred to use builder design pattern.\n\nLet's consider the person structure, which has some optional fields\n\n```java\npublic class Person {\n    private final String name;\n    private final Integer age;\n \n    // getters\n}\n```\n\nLet’s see how we can employ its power in deserialization. First of all, let’s declare a private all-arguments constructor, and a Builder class.\n```java\nprivate Person(String name, Integer age) {\n    this.name = name;\n    this.age = age;\n}\n \nstatic class Builder {\n    String name;\n    Integer age;\n    \n    Builder withName(String name) {\n        this.name = name;\n        return this;\n    }\n    \n    Builder withAge(Integer age) {\n        this.age = age;\n        return this;\n    }\n    \n    public Person build() {\n        return new Person(name, age);\n    } \n}\n```\nFirst of all, we need to mark our class with `@JsonDeserialize` annotation, passing a builder parameter with a fully qualified domain name of a builder class.\nAfter that, we need to annotate the builder class itself as `@JsonPOJOBuilder`.\n\n```java\n@JsonDeserialize(builder = Person.Builder.class)\npublic class Person {\n    //...\n    \n    @JsonPOJOBuilder\n    static class Builder {\n        //...\n    }\n}\n```\n\nA simple unit test will be:\n\n```java\nString json = \"{\\\"name\\\":\\\"Hassan\\\",\\\"age\\\":23}\";\nPerson person = new ObjectMapper().readValue(json, Person.class);\n \nassertEquals(\"Hassan\", person.getName());\nassertEquals(23, person.getAge().intValue());\n```\n\nIf your builder pattern implementation uses other prefixes for methods or uses other names than build() for the builder method Jackson also provide a handy way for you.\n\nFor example, if you have a builder class that uses the \"set\" prefix for its methods and use the create() method instead of build() for building the whole class, you have to annotate your class like:\n```java\n@JsonPOJOBuilder(buildMethodName = \"create\", withPrefix = \"set\")\nstatic class Builder {\n    String name;\n    Integer age;\n    \n    Builder setName(String name) {\n        this.name = name;\n        return this;\n    }\n    \n    Builder setAge(Integer age) {\n        this.age = age;\n        return this;\n    }\n    \n    public Person create() {\n        return new Person(name, age);\n    } \n}\n```\n\nTo deserialize JSON fields under a different name than their object counterparts,\nthe @JsonProperty annotation can be used within the builder on the appropriate fields.\n\n```java\n@JsonPOJOBuilder(buildMethodName = \"create\", withPrefix = \"set\")\nstatic class Builder {\n    @JsonProperty(\"known_as\")\n    String name;\n    Integer age;\n    //...\n}\n```\nThis will deserialize the JSON property `known_as` into the builder field `name`. If a mapping like this is not provided (and further annotations aren't supplied to handle this), an `Unrecognized field \"known_as\"` exception will be thrown during deserialization if the field is provided anyways.\n\nIf you wish to refer to properties with more than one alias for deserialization, the `@JsonAlias` annotation can be used.\n\n```java\n@JsonPOJOBuilder(buildMethodName = \"create\", withPrefix = \"set\")\nstatic class Builder {\n    @JsonProperty(\"known_as\")\n    @JsonAlias({\"identifier\", \"first_name\"})\n    String name;\n    Integer age;\n    //...\n}\n```\nThis will deserialize JSON fields with `known_as`, as well as `identifer` and `first_name` into `name`. Rather than an array of entries, a single alias can be used by specifying a string as such `JsonAlias(\"identifier\")`.  \nNote: to use the `@JsonAlias` annotation, a `@JsonProperty` annotation must also be used.\n\n\n\n\nOverall, Jackson library is very powerful in deserializing objects using builder pattern.\n \n# Contribute!\n\nWe would love to get your contribution, whether it's in form of bug reports, Requests for Enhancement (RFE), documentation, or code patches.\n\nSee [CONTRIBUTING](https://github.com/FasterXML/jackson/blob/2.x/CONTRIBUTING.md) for details on things like:\n\n* Community, ways to interact (mailing lists, gitter)\n* Issue tracking ([GitHub Issues](https://github.com/FasterXML/jackson-databind/issues))\n* Paperwork: CLA (just once before the first merged contribution)\n\n## Limitation on Dependencies by Core Components\n\nOne additional limitation exists for so-called core components (streaming api, jackson-annotations and jackson-databind): no additional dependencies are allowed beyond:\n\n* Core components may rely on any methods included in the supported JDK\n    * Minimum Java version is Java 7 for Jackson 2.7 - 2.12 of `jackson-databind` and most non-core components\n    * Minimum Java version is Java 8 for Jackson 2.13 and later\n* Jackson-databind (this package) depends on the other two (annotations, streaming).\n\nThis means that anything that has to rely on additional APIs or libraries needs to be built as an extension,\nusually a Jackson module.\n\n## Branches\n\n`3.x` branch is for developing the next major Jackson version -- 3.0 -- but there\nare active maintenance branches in which much of development happens:\n\n* `2.x` is the branch for \"next\" minor version to release (2.20 as of May 2025)\n* `2.19` is the current stable minor 2.x version\n* `2.18` is for selected backported fixes\n\nOlder branches are usually not maintained after being declared as closed\non [Jackson Releases](https://github.com/FasterXML/jackson/wiki/Jackson-Releases) page,\nbut exist just in case a rare emergency patch is needed.\nAll released versions have matching git tags (e.g. `jackson-dataformats-binary-2.12.3`).\n\n-----\n\n## Differences from Jackson 1.x\n\nProject contains versions 2.0 and above: source code for last (1.x) release, 1.9, is available at\n[Jackson-1](../../../jackson-1) repo.\n\nMain differences compared to 1.x \"mapper\" jar are:\n\n* Maven build instead of Ant\n* Java package is now `com.fasterxml.jackson.databind` (instead of `org.codehaus.jackson.map`)\n\n-----\n\n## Support\n\n### Community support\n\nJackson components are supported by the Jackson community through mailing lists, Gitter forum, Github issues. See [Participation, Contributing](../../../jackson#participation-contributing) for full details.\n\n\n### Enterprise support\n\nAvailable as part of the [Tidelift](https://tidelift.com/subscription/pkg/maven-com-fasterxml-jackson-core-jackson-databind) Subscription.\n\nThe maintainers of `jackson-databind` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/maven-com-fasterxml-jackson-core-jackson-databind?utm_source=maven-com-fasterxml-jackson-core-jackson-databind\u0026utm_medium=referral\u0026utm_campaign=enterprise\u0026utm_term=repo)\n\n-----\n\n## Further reading\n\n* [Overall Jackson Docs](../../../jackson-docs)\n* [Project wiki page](https://github.com/FasterXML/jackson-databind/wiki)\n\nRelated:\n\n* [Core annotations](https://github.com/FasterXML/jackson-annotations) package defines annotations commonly used for configuring databinding details\n* [Core parser/generator](https://github.com/FasterXML/jackson-core) package defines low-level incremental/streaming parsers, generators\n* [Jackson Project Home](../../../jackson) has links to all modules\n* [Jackson Docs](../../../jackson-docs) is project's documentation hub\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffasterxml%2Fjackson-databind","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffasterxml%2Fjackson-databind","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffasterxml%2Fjackson-databind/lists"}