Search in sources :

Example 91 with ObjectWriter

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

the class AnalyticsIncorporationComponentEventSerializationTest method testMixinWithCopy.

/**
 * Fails as actual output is:
 * {"@c":".PortletRenderExecutionEvent","timestamp":1371671516798,"serverId":"example.com","eventSessionId":"1234567890123_system_AAAAAAAAAAA","userName":"system","fname":"fname1","executionTimeNano":123450000,"parameters":{},"targeted":false,"usedPortalCache":false}
 */
@Ignore
@Test
public void testMixinWithCopy() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.findAndRegisterModules();
    // Clone from "shared" ObjectMapper
    mapper = mapper.copy();
    mapper.addMixInAnnotations(Object.class, PortletRenderExecutionEventFilterMixIn.class);
    final FilterProvider filterProvider = new SimpleFilterProvider().addFilter(PortletRenderExecutionEventFilterMixIn.FILTER_NAME, SimpleBeanPropertyFilter.filterOutAllExcept("fname", "executionTimeNano", "parameters"));
    final ObjectWriter portletEventWriter = mapper.writer(filterProvider);
    final String result = portletEventWriter.writeValueAsString(createEvent());
    assertEquals("{\"@c\":\".PortletRenderExecutionEvent\",\"fname\":\"fname1\",\"executionTimeNano\":123450000,\"parameters\":{}}", result);
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 92 with ObjectWriter

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

the class RandomForestModel method toJSON.

/**
 * {@inheritDoc}
 */
@Override
public void toJSON(Path path) {
    ObjectMapper mapper = new ObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.addMixIn(RandomForestModel.class, JSONModelMixIn.class);
    ObjectWriter writer = mapper.writerFor(RandomForestModel.class).withAttribute("formatVersion", JSONModel.JSON_MODEL_FORMAT_VERSION).withAttribute("timestamp", System.currentTimeMillis()).withAttribute("uid", "dt_" + UUID.randomUUID().toString()).withAttribute("modelClass", RandomForestModel.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 93 with ObjectWriter

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

the class GaussianNaiveBayesModel method toJSON.

/**
 * {@inheritDoc}
 */
@Override
public void toJSON(Path path) {
    ObjectMapper mapper = new ObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.addMixIn(GaussianNaiveBayesModel.class, JSONModelMixIn.class);
    ObjectWriter writer = mapper.writerFor(GaussianNaiveBayesModel.class).withAttribute("formatVersion", JSONModel.JSON_MODEL_FORMAT_VERSION).withAttribute("timestamp", System.currentTimeMillis()).withAttribute("uid", "dt_" + UUID.randomUUID().toString()).withAttribute("modelClass", GaussianNaiveBayesModel.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 94 with ObjectWriter

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

the class CompoundNaiveBayesModel method toJSON.

/**
 * {@inheritDoc}
 */
@Override
public void toJSON(Path path) {
    ObjectMapper mapper = new ObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.addMixIn(CompoundNaiveBayesModel.class, JSONModelMixIn.class);
    ObjectWriter writer = mapper.writerFor(CompoundNaiveBayesModel.class).withAttribute("formatVersion", JSONModel.JSON_MODEL_FORMAT_VERSION).withAttribute("timestamp", System.currentTimeMillis()).withAttribute("uid", "dt_" + UUID.randomUUID().toString()).withAttribute("modelClass", CompoundNaiveBayesModel.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 95 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project syndesis-qe by syndesisio.

the class AbstractEndpoint method list.

public List<T> list(String id) {
    final ObjectMapper mapper = new ObjectMapper().registerModules(new Jdk8Module());
    mapper.configure(Feature.AUTO_CLOSE_SOURCE, true);
    final ObjectWriter ow = mapper.writer();
    final Class<ListResult<T>> listtype = (Class) ListResult.class;
    log.debug("GET : {}", getEndpointUrl(Optional.ofNullable(id)));
    JsonNode response = this.createInvocation(id).get(JsonNode.class);
    ListResult<T> result = null;
    try {
        result = JsonUtils.reader().forType(listtype).readValue(response.toString());
    } catch (IOException ex) {
        log.error("" + ex);
    }
    final List<T> ts = new ArrayList<>();
    for (int i = 0; i < result.getTotalCount(); i++) {
        T con = null;
        try {
            final String json = ow.writeValueAsString(result.getItems().get(i));
            con = JsonUtils.reader().forType(type).readValue(json);
        } catch (IOException ex) {
            log.error(ex.toString());
        }
        ts.add(con);
    }
    return ts;
}
Also used : ArrayList(java.util.ArrayList) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ListResult(io.syndesis.common.model.ListResult) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) 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