下面列出了怎么用com.fasterxml.jackson.annotation.JsonInclude.Value的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Prints the usage to System.out
*
* @param errorMessage optional error message
* @param options the options object to print usage for
*/
public static void printUsage(String errorMessage, Options options) {
if (errorMessage != null) {
System.out.println(errorMessage);
System.out.println();
System.out.println();
}
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
objectMapper.setDefaultPropertyInclusion(Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS));
System.out.println("s2s is a command line tool that can either read a list of DataPackets from stdin to send over site-to-site or write the received DataPackets to stdout");
System.out.println();
System.out.println("The s2s cli input/output format is a JSON list of DataPackets. They can have the following formats:");
try {
System.out.println();
objectMapper.writeValue(System.out, Arrays.asList(new DataPacketDto("hello nifi".getBytes(StandardCharsets.UTF_8)).putAttribute("key", "value")));
System.out.println();
System.out.println("Where data is the base64 encoded value of the FlowFile content (always used for received data) or");
System.out.println();
objectMapper.writeValue(System.out, Arrays.asList(new DataPacketDto(new HashMap<>(), new File("EXAMPLE").getAbsolutePath()).putAttribute("key", "value")));
System.out.println();
System.out.println("Where dataFile is a file to read the FlowFile content from");
System.out.println();
System.out.println();
System.out.println("Example usage to send a FlowFile with the contents of \"hey nifi\" to a local unsecured NiFi over http with an input port named input:");
System.out.print("echo '");
DataPacketDto dataPacketDto = new DataPacketDto("hey nifi".getBytes(StandardCharsets.UTF_8));
dataPacketDto.setAttributes(null);
objectMapper.writeValue(System.out, Arrays.asList(dataPacketDto));
System.out.println("' | bin/s2s.sh -n input -p http");
System.out.println();
} catch (IOException e) {
e.printStackTrace();
}
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.setWidth(160);
helpFormatter.printHelp("s2s", options);
System.out.flush();
}
public OkHttpReplicationClient(final NiFiProperties properties) {
jsonCodec.setDefaultPropertyInclusion(Value.construct(Include.NON_NULL, Include.ALWAYS));
jsonCodec.setAnnotationIntrospector(new JaxbAnnotationIntrospector(jsonCodec.getTypeFactory()));
jsonSerializer = new JsonEntitySerializer(jsonCodec);
xmlSerializer = new XmlEntitySerializer();
okHttpClient = createOkHttpClient(properties);
}
@Override
public Value findPropertyInclusion(Annotated a) {
return Value.construct(Include.ALWAYS, Include.ALWAYS);
}
public ObjectMapperResolver() throws Exception {
mapper = new ObjectMapper();
mapper.setDefaultPropertyInclusion(Value.construct(Include.NON_NULL, Include.ALWAYS));
mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory()));
}