Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializer for Scala Map converts to Java Map - avoid this conversion #470

Open
pjfanning opened this issue Aug 27, 2020 · 2 comments
Open

Comments

@pjfanning
Copy link
Member

  • New iterable serializer #468 recently fix for Iterables and Iterators
  • the existing Scala Map code converts to a Java Map so it can reuse the pre-existing Java serializer
@pjfanning
Copy link
Member Author

This task will probably require copying https://github.com/FasterXML/jackson-databind/blob/166ce08b96465fc2a2a9ae385919c38ac3a3b6b4/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java (all 1000+ lines) and writing a version that handles Scala Maps natively (ie without converting the Scala map to a Java Map). After getting that working, we would need a big new suite of tests that test serializing maps with a large variety of ObjectMapper configs.

We get away (to an extent) without having a big barrage of Map serializaton tests because we reuse the Java support (at the moment).

My advice to anyone is to avoid using Maps. They put too complexity on the JSON serialization framework. Use Collections of strongly typed data.

retronym added a commit to retronym/jackson-module-scala that referenced this issue Dec 4, 2023
…g is enabled.

This Map serializer is implemented in terms of the Java version and is
somewhat fragile, as discussed in FasterXML#643 / FasterXML#470.

This commit ensures that the wrapper class is a member class in both Scala and Java.

That results in this JSON as the serializer code chooses not to put
the inner class name in the type annotation.

```
{"m":["scala.collection.immutable.Map",{"one":"one","two":"two"}]}
```

Fixes FasterXML#643
retronym added a commit to retronym/jackson-module-scala that referenced this issue Dec 4, 2023
…g is enabled.

This Map serializer is implemented in terms of the Java version and is
somewhat fragile, as discussed in FasterXML#643 / FasterXML#470.

This commit ensures that the wrapper class is a member class in both Scala and Java.

That results in this JSON as the serializer code chooses not to put
the inner class name in the type annotation.

```
{"m":["scala.collection.immutable.Map",{"one":"one","two":"two"}]}
```

Fixes FasterXML#643
retronym added a commit to retronym/jackson-module-scala that referenced this issue Dec 4, 2023
…g is enabled.

This Map serializer is implemented in terms of the Java version and is
somewhat fragile, as discussed in FasterXML#643 / FasterXML#470.

This commit ensures that the wrapper class is a member class in both Scala and Java.

That results in this JSON as the serializer code chooses not to put
the inner class name in the type annotation.

```
{"m":["scala.collection.immutable.Map",{"one":"one","two":"two"}]}
```

Fixes FasterXML#643
retronym added a commit to retronym/jackson-module-scala that referenced this issue Dec 4, 2023
This Map serializer is implemented in terms of the Java version and is
somewhat fragile, as discussed in FasterXML#643 / FasterXML#470.

This commit ensures that the wrapper class is a member class in both Scala and Java.

That results in this JSON as the serializer code chooses not to put
the inner class name in the type annotation.

```
{"m":["scala.collection.immutable.Map",{"one":"one","two":"two"}]}
```

Fixes FasterXML#643
retronym added a commit to retronym/jackson-module-scala that referenced this issue Dec 4, 2023
This Map serializer is implemented in terms of the Java version and is
somewhat fragile, as discussed in FasterXML#643 / FasterXML#470.

This commit ensures that the wrapper class is a member class in both Scala and Java.

That results in this JSON as the serializer code chooses not to put
the inner class name in the type annotation.

```
{"m":["scala.collection.immutable.Map",{"one":"one","two":"two"}]}
```

Fixes FasterXML#643
retronym added a commit to retronym/jackson-module-scala that referenced this issue Dec 4, 2023
This Map serializer is implemented in terms of the Java version and is
somewhat fragile, as discussed in FasterXML#643 / FasterXML#470.

This commit ensures that the wrapper class is a member class in both Scala and Java.

That results in this JSON as the serializer code chooses not to put
the inner class name in the type annotation.

```
{"m":["scala.collection.immutable.Map",{"one":"one","two":"two"}]}
```

Fixes FasterXML#643
pjfanning pushed a commit that referenced this issue Dec 4, 2023
This Map serializer is implemented in terms of the Java version and is
somewhat fragile, as discussed in #643 / #470.

This commit ensures that the wrapper class is a member class in both Scala and Java.

That results in this JSON as the serializer code chooses not to put
the inner class name in the type annotation.

```
{"m":["scala.collection.immutable.Map",{"one":"one","two":"two"}]}
```

Fixes #643
pjfanning pushed a commit that referenced this issue Dec 4, 2023
This Map serializer is implemented in terms of the Java version and is
somewhat fragile, as discussed in #643 / #470.

This commit ensures that the wrapper class is a member class in both Scala and Java.

That results in this JSON as the serializer code chooses not to put
the inner class name in the type annotation.

```
{"m":["scala.collection.immutable.Map",{"one":"one","two":"two"}]}
```

Fixes #643
@pjfanning
Copy link
Member Author

I'll close this for now. I suspect that the (probably small) potential perf gains are more than offset by the cost of maintaining a large custom Scala Map serializer. The Java Map serializer is pretty complicated (in jackson-databind).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant