use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project ma-core-public by infiniteautomation.
the class ExceptionCsvMessageConverter method writeInternal.
@Override
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
MediaType contentType = outputMessage.getHeaders().getContentType();
JsonEncoding encoding = getJsonEncoding(contentType);
JsonGenerator generator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(), encoding);
try {
CsvSchema schema;
if (object instanceof AbstractRestV2Exception) {
schema = this.restExceptionSchema;
object = new CsvRestException((AbstractRestV2Exception) object);
} else {
schema = this.exceptionSchema;
}
writePrefix(generator, object);
ObjectWriter objectWriter = this.objectMapper.writer().with(schema);
objectWriter.writeValue(generator, object);
writeSuffix(generator, object);
generator.flush();
} catch (JsonProcessingException ex) {
throw new HttpMessageNotWritableException("Could not write content: " + ex.getMessage(), ex);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project repseqio by repseqio.
the class VDJCGeneTest method jsonTestNoCurrentLibrary1.
@Test
public void jsonTestNoCurrentLibrary1() throws Exception {
VDJCLibrary library = VDJCLibraryRegistry.getDefaultLibrary("hs");
VDJCGene gene = library.getSafe("TRBV12-3*00");
ObjectWriter writer = GlobalObjectMappers.PRETTY.writerFor(VDJCGene.class);
ObjectReader reader = GlobalObjectMappers.PRETTY.readerFor(VDJCGene.class);
String str = writer.writeValueAsString(gene);
assertTrue(str.endsWith("/TRBV12-3*00\""));
Object geneDeserialized = reader.readValue(str);
assertTrue(geneDeserialized == gene);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project repseqio by repseqio.
the class GenerateClonesAction method go.
@Override
public void go(ActionHelper helper) throws Exception {
GCloneModel model = GModels.getGCloneModelByName(params.getModelName());
GCloneGenerator generator = model.create(new Well19937c(params.getSeed()), VDJCLibraryRegistry.getDefault());
VDJCLibrary library = VDJCLibraryRegistry.getDefault().getLibrary(model.libraryId());
try (BufferedOutputStream s = new BufferedOutputStream(params.getOutput().equals(".") ? System.out : new FileOutputStream(params.getOutput()), 128 * 1024)) {
s.write(GlobalObjectMappers.toOneLine(model.libraryId()).getBytes());
s.write('\n');
ObjectWriter writer = GlobalObjectMappers.ONE_LINE.writerFor(new TypeReference<GClone>() {
}).withAttribute(VDJCGene.JSON_CURRENT_LIBRARY_ATTRIBUTE_KEY, library);
OUTER: for (int i = 0; i < params.numberOfClones; i++) {
GClone clone = generator.sample();
for (GGene g : clone.genes.values()) {
NucleotideSequence cdr3 = g.getFeature(GeneFeature.CDR3);
if (params.isInFrame())
if (cdr3.size() % 3 != 0) {
--i;
continue OUTER;
}
if (params.isNoStops())
if (AminoAcidSequence.translateFromCenter(cdr3).containStops()) {
--i;
continue OUTER;
}
}
writer.writeValue(new CloseShieldOutputStream(s), clone);
s.write('\n');
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project repseqio by repseqio.
the class ExportCloneSequencesAction method parseExtractor.
public static DescriptionExtractor parseExtractor(String str, final VDJCLibrary library) {
Matcher matcher = extractorPatternFeatureGene.matcher(str);
if (matcher.matches())
return new DescriptionExtractorSeq(GeneFeature.parse(matcher.group(2)), null, matcher.group(1).equals("AA"));
matcher = extractorPatternFeatureClone.matcher(str);
if (matcher.matches())
return new DescriptionExtractorSeq(GeneFeature.parse(matcher.group(3)), matcher.group(2), matcher.group(1).equals("AA"));
if (str.equalsIgnoreCase("JSONClone"))
return new DescriptionExtractor() {
final ObjectWriter writer = GlobalObjectMappers.ONE_LINE.writerFor(new TypeReference<GClone>() {
}).withAttribute(VDJCGene.JSON_CURRENT_LIBRARY_ATTRIBUTE_KEY, library);
@Override
public String extract(GClone clone, GGene gene, String chain) {
try {
return writer.writeValueAsString(clone);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
};
if (str.equalsIgnoreCase("JSONGene"))
return new DescriptionExtractor() {
final ObjectWriter writer = GlobalObjectMappers.ONE_LINE.writerFor(new TypeReference<GGene>() {
}).withAttribute(VDJCGene.JSON_CURRENT_LIBRARY_ATTRIBUTE_KEY, library);
@Override
public String extract(GClone clone, GGene gene, String chain) {
try {
return writer.writeValueAsString(gene);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
};
if (str.equalsIgnoreCase("chain"))
return new DescriptionExtractor() {
@Override
public String extract(GClone clone, GGene gene, String chain) {
return chain;
}
};
matcher = extractorPatternField.matcher(str);
if (matcher.matches()) {
final boolean isGene = matcher.group(1).equalsIgnoreCase("Gene");
final String fieldName = matcher.group(2);
return new DescriptionExtractor() {
final ObjectWriter writer = isGene ? GlobalObjectMappers.ONE_LINE.writerFor(new TypeReference<GGene>() {
}).withAttribute(VDJCGene.JSON_CURRENT_LIBRARY_ATTRIBUTE_KEY, library) : GlobalObjectMappers.ONE_LINE.writerFor(new TypeReference<GClone>() {
}).withAttribute(VDJCGene.JSON_CURRENT_LIBRARY_ATTRIBUTE_KEY, library);
@Override
public String extract(GClone clone, GGene gene, String chain) {
try {
String str = writer.writeValueAsString(isGene ? gene : clone);
JsonNode tree = GlobalObjectMappers.ONE_LINE.readTree(str);
JsonNode targetNode = tree.get(fieldName);
return targetNode == null ? "" : targetNode.asText();
} catch (java.io.IOException e) {
throw new RuntimeException(e);
}
}
};
}
throw new IllegalArgumentException("Can't parse description extractor: " + str);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project drill by apache.
the class TestQueryProfiles method runQuery.
private int runQuery(QueryWrapper query) throws IOException {
ObjectWriter writer = mapper.writerFor(QueryWrapper.class);
String json = writer.writeValueAsString(query);
String url = String.format("http://localhost:%d/query.json", portNumber);
Request request = new Request.Builder().url(url).post(RequestBody.create(json, JSON_MEDIA_TYPE)).build();
try (Response response = httpClient.newCall(request).execute()) {
return response.code();
}
}
Aggregations