use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project data-prep by Talend.
the class ConfiguredCacheWriter method write.
public void write(final ContentCacheKey key, final Object object) throws IOException {
final ObjectMapper mapper = new ObjectMapper();
final ObjectWriter objectWriter = mapper.writerFor(object.getClass());
try (final OutputStream output = contentCache.put(key, ttl)) {
objectWriter.writeValue(output, object);
LOGGER.debug("New metadata cache entry -> {}.", key.getKey());
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project cloudconductor-agent-redhat by cinovo.
the class AbstractApiHandler method request.
protected final HTTPRequest request(String path, Object obj, JavaType type) throws SerializationException {
try {
ObjectWriter bodyWriter = AbstractApiHandler.mapper.writer();
if ((type != null) && ((obj instanceof Set) || (obj instanceof List))) {
bodyWriter = bodyWriter.forType(type);
}
String body = bodyWriter.writeValueAsString(obj);
return this.request(path).body(body).header("Content-Type", MediaType.APPLICATION_JSON);
} catch (IOException e) {
throw new SerializationException();
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project rskj by rsksmart.
the class NetworkStateExporter method exportStatus.
public boolean exportStatus(String outputFile, String accountKey, boolean exportStorageKeys, boolean exportCode) {
RepositorySnapshot frozenRepository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
File dumpFile = new File(outputFile);
try (FileWriter fw = new FileWriter(dumpFile.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw)) {
JsonNodeFactory jsonFactory = new JsonNodeFactory(false);
ObjectNode mainNode = jsonFactory.objectNode();
if (accountKey.length() == 0) {
exportAllAccounts(mainNode, frozenRepository, exportStorageKeys, exportCode);
} else {
RskAddress addr = new RskAddress(accountKey);
exportAccount(addr, mainNode, frozenRepository, exportStorageKeys, exportCode);
}
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
bw.write(writer.writeValueAsString(mainNode));
return true;
} catch (Exception e) {
logger.error(e.getMessage(), e);
panicProcessor.panic("dumpstate", e.getMessage());
return false;
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project keycloak by keycloak.
the class Serialization method from.
public static <T> T from(T orig, T target) {
if (orig == null) {
return null;
}
@SuppressWarnings("unchecked") final Class<T> origClass = (Class<T>) orig.getClass();
// Naive solution but will do.
try {
ObjectReader reader = MAPPER.readerForUpdating(target);
ObjectWriter writer = WRITERS.computeIfAbsent(origClass, MAPPER::writerFor);
final T res;
res = reader.readValue(writer.writeValueAsBytes(orig));
if (res != target) {
throw new IllegalStateException("Should clone into desired target");
}
return res;
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project ignite by apache.
the class DiscreteNaiveBayesModel method toJSON.
/**
* {@inheritDoc}
*/
@Override
public void toJSON(Path path) {
ObjectMapper mapper = new ObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.addMixIn(DiscreteNaiveBayesModel.class, JSONModelMixIn.class);
ObjectWriter writer = mapper.writerFor(DiscreteNaiveBayesModel.class).withAttribute("formatVersion", JSONModel.JSON_MODEL_FORMAT_VERSION).withAttribute("timestamp", System.currentTimeMillis()).withAttribute("uid", "dt_" + UUID.randomUUID().toString()).withAttribute("modelClass", DiscreteNaiveBayesModel.class.getSimpleName());
try {
File file = new File(path.toAbsolutePath().toString());
writer.writeValue(file, this);
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations