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);
}
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();
}
}
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();
}
}
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();
}
}
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;
}
Aggregations