question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for handling `Map.Entry`

See original GitHub issue

Since use of Map.Entry as type is relatively common for constructs like Iterable<Map.Entry<>> or List<Map.Entry<>>, it’d make sense to support it. By default, serialization should probably occur as JSON Object with just one entry. Deserializer will need to do bit of verification after entry, to give more meaningful error for possible case of structural mismatch.

A potential added twist is whether to try to optimize more compact forms: specifically, Iterable (or Iterator) of Map.Entry instances could conceivably be simply serialized as JSON Object, instead of JSON Array of single-entry JSON Objects.

One possibility would be to initially support deserialization of such structure (as it should be detectable from JSON Array vs JSON Object difference); and later on maybe add support for serialization as well, using @JsonFormat to indicate difference.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
cowtowncodercommented, Jul 25, 2017

@pedro93 You can use:

    @JsonFormat(shape=JsonFormat.Shape.OBJECT)

annotation on property, to serialize “as POJO” (i.e. with 2 fields); and:

@JsonFormat(shape=JsonFormat.Shape.NATURAL)

to serialize using new compact notation.

And to set this as the default, you should be able to use:

        mapper.configOverride(Map.Entry.class)
            .setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.OBJECT)

as “per-type config override”.

4reactions
rlubkecommented, Oct 6, 2017

@cowtowncoder

Sorry to pile on here. We’re looking to control the wire format of our custom Map.Entry class. I’ve set:

mapper.configOverride(Map.Entry.class) .setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.OBJECT)

Per your instructions, but it doesn’t seem to work.

We can’t, or rather would like to avoid annotating the custom Map.Entry implementation to maintain separate between the serialization layer and the object layer as we have several different serializers.
We also can’t reference the concrete type from the serialization module.

Using Jackson 2.9.1.

Any thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add support for handling `Map.Entry` · Issue #565 - GitHub
Since use of Map.Entry as type is relatively common for constructs like Iterable > or List >, it'd make sense to support it....
Read more >
Using the Map.Entry Java Class - Baeldung
In this tutorial, we'll compare different methods of map iteration, highlighting when it may be beneficial to use Map.Entry.
Read more >
Map.Entry interface in Java with example - GeeksforGeeks
Map.Entry interface in Java provides certain methods to access the entry in the Map. By gaining access to the entry of the Map...
Read more >
How to put an Entry into a Map? - java - Stack Overflow
The MyMap interface is just an interface that extends the Map interface by adding one more method, the public default V put(Entry<K,V> entry)...
Read more >
Map (Java Platform SE 8 ) - Oracle Help Center
An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found