Created
June 15, 2022 18:06
-
-
Save lucasnata/97bb8f77f9e9c9493245d464b0b341d6 to your computer and use it in GitHub Desktop.
HashMap to List JSON output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HashMapSerializer extends JsonSerializer<Map<Long, Object>> { | |
ObjectMapper mapper = new ObjectMapper(); | |
@Override | |
public void serialize(Map<Long, Object> userMap, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { | |
jsonGenerator.writeString(mapper.writeValueAsString(userMap.values())); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
@JsonSerialize(using = HashSerializer.class) | |
private final Map<Long, Product> products; | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment