All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.modelmapper.jackson.JacksonModule Maven / Gradle / Ivy

package org.modelmapper.jackson;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.modelmapper.ModelMapper;
import org.modelmapper.Module;

/**
 * ModelMapper module for Jackson
 *
 * @author Chun Han Hsiao
 */
public class JacksonModule implements Module {
  private ObjectMapper objectMapper;

  public JacksonModule() {
    this(new ObjectMapper());
  }

  public JacksonModule(ObjectMapper objectMapper) {
    this.objectMapper = objectMapper;
  }

  @Override
  public void setupModule(ModelMapper modelMapper) {
    modelMapper.getConfiguration().addValueReader(new JsonNodeValueReader());
    modelMapper.getConfiguration().getConverters().add(0, new PrimitiveJsonNodeConverter());
    modelMapper.getConfiguration().getConverters().add(0, new ArrayNodeToCollectionConverter());
    modelMapper.getConfiguration().getConverters().add(0, new CollectionToArrayNodeConverter(objectMapper));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy