You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
895 B
30 lines
895 B
package db.model;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
public class ToJson {
|
|
|
|
protected Logger log=LogManager.getLogger();
|
|
|
|
private static ObjectMapper objectMapper=new ObjectMapper();
|
|
|
|
protected void mapperConfig(){
|
|
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
|
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
try {
|
|
return objectMapper.writeValueAsString(this);
|
|
} catch (JsonProcessingException e) {
|
|
log.info(e);
|
|
return super.toString();
|
|
}
|
|
}
|
|
}
|
|
|