本文整理汇总了Java中com.fasterxml.jackson.databind.MappingJsonFactory类的典型用法代码示例。如果您正苦于以下问题:Java MappingJsonFactory类的具体用法?Java MappingJsonFactory怎么用?Java MappingJsonFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MappingJsonFactory类属于com.fasterxml.jackson.databind包,在下文中一共展示了MappingJsonFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WampClient
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
public WampClient(DataFormat dataFormat) {
this.isBinary = dataFormat != DataFormat.JSON;
this.result = new CompletableFutureWebSocketHandler();
this.headers = new WebSocketHttpHeaders();
switch (dataFormat) {
case CBOR:
this.jsonFactory = new ObjectMapper(new CBORFactory()).getFactory();
this.headers.setSecWebSocketProtocol(WampSubProtocolHandler.CBOR_PROTOCOL);
break;
case MSGPACK:
this.jsonFactory = new ObjectMapper(new MessagePackFactory()).getFactory();
this.headers.setSecWebSocketProtocol(WampSubProtocolHandler.MSGPACK_PROTOCOL);
break;
case JSON:
this.jsonFactory = new MappingJsonFactory(new ObjectMapper());
this.headers.setSecWebSocketProtocol(WampSubProtocolHandler.JSON_PROTOCOL);
break;
case SMILE:
this.jsonFactory = new ObjectMapper(new SmileFactory()).getFactory();
this.headers.setSecWebSocketProtocol(WampSubProtocolHandler.SMILE_PROTOCOL);
break;
default:
this.jsonFactory = null;
}
}
示例2: GenericJacksonWayGraphOutputFormat
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
public GenericJacksonWayGraphOutputFormat(ISegmentOutputFormat<T> segmentOutputFormat,
IAdapter<IGraphVersionMetadataDTO, IWayGraphVersionMetadata> adapter,
OutputStream stream,
JsonGenerator generator)
{
this.segmentOutputFormat = segmentOutputFormat;
this.adapter = adapter;
if (generator == null) {
try {
this.generator = new MappingJsonFactory().createGenerator(stream, JsonEncoding.UTF8);
this.generator.useDefaultPrettyPrinter();
} catch (IOException e) {
log.error("error creating jackson json factory", e);
}
} else {
this.generator = generator;
}
}
示例3: GenericJacksonSegmentOutputFormat
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
public GenericJacksonSegmentOutputFormat(ISegmentAdapterRegistry<? extends IBaseSegmentDTO, T> adapterRegistry,
OutputStream stream, JsonGenerator generator, int flushBatchCount)
{
this.adapterRegistry = adapterRegistry;
if (generator == null) {
try {
this.generator = new MappingJsonFactory().createGenerator(new BufferedOutputStream(stream), JsonEncoding.UTF8);
this.generator.useDefaultPrettyPrinter();
} catch (IOException e) {
log.error("error creating jackson json factory", e);
}
}
if (flushBatchCount > 0 ) {
this.flushBatchCount = flushBatchCount;
} else {
log.warn("flushBatchCount ignored, can not be negative or 0");
}
}
示例4: convert
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
@Override
public String convert(final List<ComplexNestedType> object) {
try {
StringWriter writer = new StringWriter();
JsonFactory jsonFactory = new MappingJsonFactory();
JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
jsonGenerator.writeObject(object);
return writer.toString();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: jsonExtractSubnetMask
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
/**
* Extracts subnet mask from a JSON string
* @param fmJson The JSON formatted string
* @return The subnet mask
* @throws IOException If there was an error parsing the JSON
*/
public static String jsonExtractSubnetMask(String fmJson) throws IOException {
String subnet_mask = "";
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createParser(fmJson);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n == "subnet-mask") {
subnet_mask = jp.getText();
break;
}
}
return subnet_mask;
}
示例6: deserialize
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
@Override
public Data<Resource> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException {
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
ObjectMapper mapper = new MappingJsonFactory().getCodec();
if (node.isArray()) {
List<Resource> resources = new ArrayList<>();
for (JsonNode n : node) {
Resource r = mapper.convertValue(n, Resource.class);
resources.add(r);
}
return new Data<>(resources);
}
Resource resource = mapper.convertValue(node, Resource.class);
return new Data<>(resource);
}
示例7: wampWebSocketHandlerMapping
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
@Bean
public HandlerMapping wampWebSocketHandlerMapping() {
WebSocketHandler handler = subProtocolWebSocketHandler();
handler = decorateWebSocketHandler(handler);
WebMvcWampEndpointRegistry registry = new WebMvcWampEndpointRegistry(handler,
getTransportRegistration(), messageBrokerSockJsTaskScheduler(),
new MappingJsonFactory(lookupObjectMapper()));
List<HandshakeInterceptor> handshakeInterceptors = new ArrayList<>();
addHandshakeInterceptors(handshakeInterceptors);
registry.addHandshakeInterceptors(handshakeInterceptors);
registerWampEndpoints(registry);
return registry.getHandlerMapping();
}
示例8: CompletableFutureWebSocketHandler
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
public CompletableFutureWebSocketHandler(int expectedNoOfResults) {
this.jsonFactory = new MappingJsonFactory(new ObjectMapper());
this.msgpackFactory = new ObjectMapper(new MessagePackFactory()).getFactory();
this.cborFactory = new ObjectMapper(new CBORFactory()).getFactory();
this.smileFactory = new ObjectMapper(new SmileFactory()).getFactory();
this.timeout = getTimeoutValue();
this.welcomeMessageFuture = new CompletableFuture<>();
this.reset(expectedNoOfResults);
}
示例9: testSerialize
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
@Test
public void testSerialize() throws IOException {
String test = "[{\"name\":\"HalloHallo\",\"segmentId\":12345}]";
InputStream stream = new ByteArrayInputStream( test.getBytes() );
JsonFactory factory = new MappingJsonFactory();
JsonParser parser = factory.createParser(stream);
JsonToken token = parser.nextToken();
if (token == JsonToken.START_ARRAY) {
do {
parser.nextToken();
DefaultSegmentXInfoDTO segmentXInfoDTO = parser.readValueAs(DefaultSegmentXInfoDTO.class);
} while (token == JsonToken.END_ARRAY);
}
}
示例10: unconvert
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
@Override
public List<ComplexNestedType> unconvert(String obj) {
try {
JsonFactory jsonFactory = new MappingJsonFactory();
JsonParser jsonParser = jsonFactory.createJsonParser(new StringReader(obj));
return jsonParser.readValueAs(new TypeReference<List<ComplexNestedType>>() {
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例11: jsonToHostDefinition
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
protected void jsonToHostDefinition(String json, HostDefinition host) throws IOException {
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
else if (n.equals("attachment")) {
while (jp.nextToken() != JsonToken.END_OBJECT) {
String field = jp.getCurrentName();
if (field.equals("id")) {
host.attachment = jp.getText();
} else if (field.equals("mac")) {
host.mac = jp.getText();
}
}
}
}
jp.close();
}
示例12: getEntryNameFromJson
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
/**
* Gets the entry name of a flow mod
* @param fmJson The OFFlowMod in a JSON representation
* @return The name of the OFFlowMod, null if not found
* @throws IOException If there was an error parsing the JSON
*/
public static String getEntryNameFromJson(String fmJson) throws IOException{
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createParser(fmJson);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n == StaticFlowEntryPusher.COLUMN_NAME)
return jp.getText();
}
return null;
}
示例13: jsonToHostDefinition
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
protected void jsonToHostDefinition(String json, HostDefinition host) throws IOException {
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
else if (n.equals("attachment")) {
while (jp.nextToken() != JsonToken.END_OBJECT) {
String field = jp.getCurrentName();
if (field.equals("id")) {
host.attachment = jp.getText();
} else if (field.equals("mac")) {
host.mac = jp.getText();
}
}
}
}
jp.close();
}
示例14: getEntryNameFromJson
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
/**
* Gets the entry name of a flow mod
* @param fmJson The OFFlowMod in a JSON representation
* @return The name of the OFFlowMod, null if not found
* @throws IOException If there was an error parsing the JSON
*/
public static String getEntryNameFromJson(String fmJson) throws IOException{
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(fmJson);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n == StaticFlowEntryPusher.COLUMN_NAME)
return jp.getText();
}
return null;
}
示例15: jsonExtractSubnetMask
import com.fasterxml.jackson.databind.MappingJsonFactory; //导入依赖的package包/类
/**
* Extracts subnet mask from a JSON string
* @param fmJson The JSON formatted string
* @return The subnet mask
* @throws IOException If there was an error parsing the JSON
*/
public static String jsonExtractSubnetMask(String fmJson) throws IOException {
String subnet_mask = "";
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(fmJson);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n == "subnet-mask") {
subnet_mask = jp.getText();
break;
}
}
return subnet_mask;
}