Giter VIP home page Giter VIP logo

circe-jackson's Introduction

circe-jackson

Build status Coverage status Gitter Maven Central

This project provides support for using Jackson for JSON parsing and printing with circe, a Scala library for encoding and decoding JSON to Scala types.

Several versions of Jackson are still in widespread use, and io.circe.jackson is cross-published with support for Jackson 2.5, 2.6, 2.7, and 2.8. Each module has a two-digit suffix indicating its Jackson version (circe-jackson28 supports Jackson 2.8, etc.).

The project source is mostly shared, with version-specific code in separate source trees. Note that the source supporting Jackson 2.6 and 2.7 is identical, so these version share a source tree.

There's not a lot of documentation, but the API is fairly minimal, and we do publish the API docs.

Until the 0.6.2 release, the circe-jackson module lived in the main circe project, so if you're interested in finding the source for earlier releases, please check the release tags there.

Jackson vs. Jawn

The primary purpose of this module is to support circe adopters who already have a Jackson dependency and would like to avoid adding a dependency on Jawn.

In general new projects or projects that aren't currently using Jackson should prefer circe-jawn to circe-jackson. Not all guarantees that hold for Jawn-based parsing and the default printer will hold for the Jackson-based versions. Jackson's handling of numbers in particular differs significantly: it doesn't distinguish positive and negative zeros, it may truncate large JSON numbers or simply fail to parse them, it may print large numbers as strings, etc.

In our benchmarks circe-jawn outperforms circe-jackson on parsing that involves a lot of JSON objects, but the default circe printer is not as fast as circe-jackson's:

Benchmark                       Mode  Cnt      Score     Error  Units
ParsingBenchmark.parseFoosC    thrpt  100   3421.718 ±  17.133  ops/s
ParsingBenchmark.parseFoosCJ   thrpt  100   2230.284 ±  20.305  ops/s
ParsingBenchmark.parseIntsC    thrpt  100  16894.760 ±  70.032  ops/s
ParsingBenchmark.parseIntsCJ   thrpt  100  17093.963 ± 125.049  ops/s

Benchmark                       Mode  Cnt      Score     Error  Units
PrintingBenchmark.printFoosC   thrpt  100   4173.857 ±  18.818  ops/s
PrintingBenchmark.printFoosCJ  thrpt  100   4997.025 ±  22.633  ops/s
PrintingBenchmark.printIntsC   thrpt  100  25834.763 ±  92.639  ops/s
PrintingBenchmark.printIntsCJ  thrpt  100  56459.382 ± 182.105  ops/s

If your project needs JSON printing to be as fast as possible, it may be worth evaluating circe-jackson in your own benchmarks (especially since it's essentially a drop-in replacement—simply add the appropriate version to your build, import io.circe.jackson.syntax._, and call doc.jacksonPrint on your Json values instead of e.g. doc.noSpaces).

Contributors and participation

This project is adapted from the Jackson-based parsing code in Play JSON (another excellent Scala JSON library).

All circe projects support the Typelevel code of conduct and we want all of their channels (Gitter, GitHub, etc.) to be welcoming environments for everyone.

Please see the circe contributors' guide for details on how to submit a pull request.

License

circe-jackson is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

circe-jackson's People

Contributors

anusha-mallampati-ck avatar asoltysik avatar benfradet avatar biochimia avatar diesalbla avatar etspaceman avatar jensraaby avatar lhotari avatar n4to4 avatar scala-steward avatar travisbrown avatar travisbrown-stripe avatar vkostyukov avatar zarthross avatar zmccoy avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

circe-jackson's Issues

0.14.0 Compliant Release

Looking to get a version of circe-jackson that is compliant with the 0.14.x series for Circe.

Using JsonParser.Feature.* ?

Is there currently a way to enable features such as JsonParser.Feature.ALLOW_TRAILING_COMMA (this is how you know I have to deal with malformed json)?

Incorrect Jackson Version Naming 212 Vs 213?

Hey, just a quick question about this part of the build.sbt: Shouldn't the Circe project be name circe-jackson213 instead of circe-jackson212 or am I missing something here? In case I am correct just let me know and I will make a tiny PR - thanks! If I am not I am curious to know what I am missing 😅

Port 0.7.0 changes back from main circe repository

When I split circe-jackson into its own project I started with the current circe master branch, but had to change some things in order to be able to publish an 0.6.x version depending on circe 0.6.1.

We'll need to update this new repository with the post-0.6.x changes from the main project. This should be relatively straightforward but not just a matter of copy-paste.

Weird mapper inconsistency based on how the json is created

I have noticed a weird inconsistency depending on how the json is created when interacting with the mapper (c.f. #48):

import cats.syntax.either._
import cats.syntax.eq._
import io.circe.Json
import io.circe.literal._
import io.circe.syntax._

val json1 = json"""{"latitude": 43.1, "longitude": 32.1}""" // same with im.circe.parser.parse
val json2 = Json.obj("latitude" := Json.fromDoubleOrNull(43.1), "longitude" := Json.fromDoubleOrNull(32.1))

println(json1 === json2) // true

// a lib I'm using requires me to convert it to an object
val pojo1 = io.circe.jackson.mapper.convertValue(json1, classOf[Object])
val pojo2 = io.circe.jackson.mapper.convertValue(json2, classOf[Object])

println(pojo1 == pojo2) // false

// String
val c1 = Either.catchNonFatal(
  pojo1.asInstanceOf[java.util.HashMap[Object, Object]].get("latitude").getClass)
// Double
val c2 = Either.catchNonFatal(
  pojo2.asInstanceOf[java.util.HashMap[Object, Object]].get("latitude").getClass)

println(c1)
println(c2)

using circe-literal or parse doubles get turned to strings whereas they stay doubles when creating jsons in line.

Here is a scastie reproducing the issue https://scastie.scala-lang.org/VMydlc7ITW2PYBn2NgizUw . However it relies on #48.

Stricter deserialization of numeric values

CirceJsonDeserializer.deserialize uses JsonBigDecimal in all numeric cases.

In my use case, it'd be nice to have JsonLong instead of JsonBigDecimal when the value can fit into Long range (-9223372036854775808 - 9223372036854775807).

A flag/configuration field could also be introduced to specify whether deserialization should pick strictest type or vice versa.

circeToJackson maps integer value bigger than java.lang.Long.MAX_VALUE into DecimalNode

import com.fasterxml.jackson.databind.{ ObjectMapper, JsonNode }
import io.circe.literal._
import io.circe.jackson.circeToJackson

def getJsonNodeFromStringContent(content: String): JsonNode =
  (new ObjectMapper).readTree(content)

val circeJson = circeToJackson(json"""9223372036854775809""")
val jacksonJson = getJsonNodeFromStringContent("9223372036854775809")

println(s"circeJson is ${circeJson.getClass})
println(s"jacksonJson is ${jacksonJson.getClass})
circeJson is class com.fasterxml.jackson.databind.node.DecimalNode
jacksonJson is class com.fasterxml.jackson.databind.node.BigIntegerNode

compilation failure in Scala 2.13 community build

in the Scala 2.13 community build at e.g. we see

[circe-jackson] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.16/project-builds/circe-jackson-01df699a723995e667f4595b6825f5a6458667db/shared/src/main/scala/io/circe/jackson/package.scala:76:48: overloaded method value setAll with alternatives:
[circe-jackson] [error]   (x$1: com.fasterxml.jackson.databind.node.ObjectNode)com.fasterxml.jackson.databind.JsonNode <and>
[circe-jackson] [error]   (x$1: java.util.Map[String, _ <: com.fasterxml.jackson.databind.JsonNode])com.fasterxml.jackson.databind.JsonNode
[circe-jackson] [error]  cannot be applied to (Iterable[(String, com.fasterxml.jackson.databind.JsonNode)])
[circe-jackson] [error]     obj => JsonNodeFactory.instance.objectNode.setAll(obj.toMap.mapValues(circeToJackson).asJava)
[circe-jackson] [error]                                                ^
[circe-jackson] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.16/project-builds/circe-jackson-01df699a723995e667f4595b6825f5a6458667db/shared/src/main/scala/io/circe/jackson/package.scala:76:48: overloaded method value setAll with alternatives:
[circe-jackson] [error]   (x$1: com.fasterxml.jackson.databind.node.ObjectNode)com.fasterxml.jackson.databind.JsonNode <and>
[circe-jackson] [error]   (x$1: java.util.Map[String, _ <: com.fasterxml.jackson.databind.JsonNode])com.fasterxml.jackson.databind.JsonNode
[circe-jackson] [error]  cannot be applied to (Iterable[(String, com.fasterxml.jackson.databind.JsonNode)])
[circe-jackson] [error]     obj => JsonNodeFactory.instance.objectNode.setAll(obj.toMap.mapValues(circeToJackson).asJava)
[circe-jackson] [error]                                                ^

this will probably come up if/when you try to upgrade to Scala 2.13.0-RC1

Could we do a release?

Hi everyone,

I have a project using Jackson 2.13.4 and would like to use circe-jackson213. It seems it exists: #307, but a release hasn't been done since, so the module is not published on Maven.

Would it be possible to do a release?

Thanks!

Find some co-owners or maintainers

While I'm personally committed to maintaining this project and publishing releases in sync with the rest of circe, it'd be great to get one or two other people on board to help with issues (like #1, #2, and #3), reviewing, and publishing.

If you're interested in joining this project as a co-owner or maintainer, please contact me on Gitter or by email at travisrobertbrown at gmail dot com.

Update MiMa configuration

Right now only one module (circe-jackson25) is set up to have binary compatibility check, since it's the only module that existed before today's 0.6.2 release. Now that releases are out in the world for all four modules, it'd be great to have MiMa checking for all of them.

CirceJsonDeserializer fails when using Jackson's MappingIterator

My usecase is to use CirceJsonDeserializer in a library that uses Jackson's MappingIterator to deserialize an array of JSON objects which are part of a larger JSON document. I'd like to get Circe Json instances returned from this library. There is a small bug in circe-jackson which prevents using CirceJsonDeserializer in this way.

This is the exception I get:

We weren't reading an object, something went wrong
java.lang.RuntimeException: We weren't reading an object, something went wrong
	at io.circe.jackson.CirceJsonDeserializer.deserialize(CirceJsonDeserializer.scala:74)
	at io.circe.jackson.CirceJsonDeserializer.deserialize(CirceJsonDeserializer.scala:40)
	at io.circe.jackson.CirceJsonDeserializer.deserialize(CirceJsonDeserializer.scala:35)
	at com.fasterxml.jackson.databind.MappingIterator.nextValue(MappingIterator.java:277)
	at com.fasterxml.jackson.databind.MappingIterator.next(MappingIterator.java:192)

I debugged the problem and found out the CirceJsonDeserializer is consuming one extra token and that's causing the failure.

I have a failing test case and fix for the issue, I'll send a PR.

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.