Bravo
Bravo

Reputation: 1139

How to apply jackson-databind deserializer on map key?

I have the following field:

@JsonProperty("data")
@JsonDeserialize(using = CustomJsonDateDeserializer.class)
private HashMap<Date,String> data;

I want to apply CustomJsonDateDeserializer only on map keys.

Thank you in advance

Upvotes: 2

Views: 1025

Answers (1)

Bravo
Bravo

Reputation: 1139

After carefully reading the documentation, I found the solution to my problem.

@JsonProperty("data")
@JsonDeserialize(keyUsing = CustomJsonDateDeserializer.class, keyAs = Date.class)
private HashMap<Date,String> data;

CustomJsonDateDeserializer has to extend the KeyDeserializer class.

Upvotes: 3

Related Questions