Search in sources :

Example 26 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project ignite by apache.

the class DecisionTreeModel method toJSON.

/**
 * {@inheritDoc}
 */
@Override
public void toJSON(Path path) {
    ObjectMapper mapper = new ObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.addMixIn(DecisionTreeModel.class, JSONModelMixIn.class);
    ObjectWriter writer = mapper.writerFor(DecisionTreeModel.class).withAttribute("formatVersion", JSONModel.JSON_MODEL_FORMAT_VERSION).withAttribute("timestamp", System.currentTimeMillis()).withAttribute("uid", "dt_" + UUID.randomUUID().toString()).withAttribute("modelClass", DecisionTreeModel.class.getSimpleName());
    try {
        File file = new File(path.toAbsolutePath().toString());
        writer.writeValue(file, this);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 27 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project ignite by apache.

the class GDBModel method toJSON.

/**
 * {@inheritDoc}
 */
@Override
public void toJSON(Path path) {
    ObjectMapper mapper = new ObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.addMixIn(GDBModel.class, JSONModelMixIn.class);
    ObjectWriter writer = mapper.writerFor(GDBModel.class).withAttribute("formatVersion", JSONModel.JSON_MODEL_FORMAT_VERSION).withAttribute("timestamp", System.currentTimeMillis()).withAttribute("uid", "dt_" + UUID.randomUUID().toString()).withAttribute("modelClass", GDBModel.class.getSimpleName());
    try {
        File file = new File(path.toAbsolutePath().toString());
        writer.writeValue(file, this);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 28 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project CzechIdMng by bcvsolutions.

the class LoginControllerRestTest method serialize.

private String serialize(Map<String, String> login) throws IOException {
    StringWriter sw = new StringWriter();
    ObjectWriter writer = getMapper().writerFor(HashMap.class);
    writer.writeValue(sw, login);
    // 
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter)

Example 29 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project navajo by Dexels.

the class BaseRuntimeImpl method writeNode.

@Override
public void writeNode(JsonNode node) throws IOException {
    setMimeType("application/json; charset=utf-8");
    ObjectWriter writer = mapper.writer().withDefaultPrettyPrinter();
    writer.writeValue(getOutputWriter(), node);
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter)

Example 30 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project navajo by Dexels.

the class ServletArticleRuntimeImpl method commit.

@Override
public void commit() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode rootNode;
    try {
        rootNode = mapper.readValue(writer.toString(), JsonNode.class);
    } catch (JsonParseException e) {
        logger.error("JSON parse error: ", e);
        response.getWriter().write("Invalid JSON follows:\n");
        response.getWriter().write(writer.toString());
        return;
    }
    ObjectWriter writer = mapper.writer().withDefaultPrettyPrinter();
    writer.writeValue(response.getWriter(), rootNode);
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)140 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)61 IOException (java.io.IOException)31 Test (org.junit.Test)30 File (java.io.File)17 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)15 ArrayList (java.util.ArrayList)12 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)11 JavaType (com.fasterxml.jackson.databind.JavaType)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)7 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 StringWriter (java.io.StringWriter)7 Map (java.util.Map)7 JCommander (com.beust.jcommander.JCommander)6 ParameterException (com.beust.jcommander.ParameterException)6 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)6 RateLimiter (com.google.common.util.concurrent.RateLimiter)6 FileInputStream (java.io.FileInputStream)6