This is my custom JSON Serializer and I'm trying to register it as a module. Here is what I have so far.
public class MaptoListSerializer extends JsonSerializer<Map<String, Car<?, ?>>> {
@Override
public void serialize(Map<String, Car<?, ?>> value, JsonGenerator gen, SerializerProvider serializers)throws IOException, JsonProcessingException {
gen.writeObject(value.values());
}
}
Here is my module class that I created (Can't seem to add serializer).
public class CustomModule extends SimpleModule {
private static final long serialVersionUID = -9105685985325373621L;
public CustomModule() {
super("CustomModule");
}
@Override
public void setupModule(SetupContext context) {
SimpleSerializers serializers = new SimpleSerializers();
//THIS DOESN'T WORK . HOW DO I ADD THE SERIALIZER?
serializers.addSerializer(HashMap.class, new MaptoListSerializer ());
context.addSerializers(serializers);
}
}
Here is how Object mapper it used (This works)
mapper = new ObjectMapper();
mapper.registerModule(new CustomModule());