本文整理汇总了Java中org.codehaus.jackson.map.DeserializationContext类的典型用法代码示例。如果您正苦于以下问题:Java DeserializationContext类的具体用法?Java DeserializationContext怎么用?Java DeserializationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DeserializationContext类属于org.codehaus.jackson.map包,在下文中一共展示了DeserializationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public Directive deserialize(JsonParser jp, DeserializationContext ctx)
throws IOException {
ObjectReader reader = ObjectMapperUtil.instance().getObjectReader();
ObjectNode obj = (ObjectNode) reader.readTree(jp);
Iterator<Map.Entry<String, JsonNode>> elementsIterator = obj.getFields();
String rawMessage = obj.toString();
DialogRequestIdHeader header = null;
JsonNode payloadNode = null;
ObjectReader headerReader =
ObjectMapperUtil.instance().getObjectReader(DialogRequestIdHeader.class);
while (elementsIterator.hasNext()) {
Map.Entry<String, JsonNode> element = elementsIterator.next();
if (element.getKey().equals("header")) {
header = headerReader.readValue(element.getValue());
}
if (element.getKey().equals("payload")) {
payloadNode = element.getValue();
}
}
if (header == null) {
throw ctx.mappingException("Missing header");
}
if (payloadNode == null) {
throw ctx.mappingException("Missing payload");
}
return createDirective(header, payloadNode, rawMessage);
}
示例2: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public Window deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
JsonNode node = jp.getCodec().readTree(jp);
Double value = node.get("value").asDouble();
Window window = new Window(value);
if (node.has("bounds")) {
long lowerBound = node.get("bounds").get(0).asLong();
long upperBound = node.get("bounds").get(1).asLong();
window.withLowerBound(lowerBound).withUpperBound(upperBound);
}
return window;
}
示例3: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public StatePair deserialize(JsonParser parser,
DeserializationContext context)
throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) parser.getCodec();
// set the state-pair object tree
ObjectNode statePairObject = (ObjectNode) mapper.readTree(parser);
Class<?> stateClass = null;
try {
stateClass =
Class.forName(statePairObject.get("className").getTextValue().trim());
} catch (ClassNotFoundException cnfe) {
throw new RuntimeException("Invalid classname!", cnfe);
}
String stateJsonString = statePairObject.get("state").toString();
State state = (State) mapper.readValue(stateJsonString, stateClass);
return new StatePair(state);
}
示例4: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public ProducedEventsResult deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
JsonNode node = jp.getCodec().readTree(jp);
if (node.isArray()) {
List<ProducedEventResult> responses = new ArrayList<>();
Iterator<JsonNode> it = node.iterator();
while (it.hasNext()) {
JsonNode n = it.next();
responses.add(new ProducedEventResult(n.get("created").asBoolean()));
}
return new ProducedEventsResult(responses);
} else {
String reason = node.get("reason").asText();
return new ProducedEventsResult(reason);
}
}
示例5: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public TopicRecord deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
JsonNode node = jp.getCodec().readTree(jp);
String topic = node.get("topic").asText();
long partition = node.get("partition").asLong();
long offset = node.get("offset").asLong();
long timestamp = node.get("timestamp").asLong();
String key = null;
if (node.has("key")) {
key = node.get("key").asText();
}
Map<Object, Object> value = new ObjectMapper().readValue(node.get("value").toString(), Map.class);
return new TopicRecord(topic, key, partition, offset, timestamp, value);
}
示例6: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public SubscribeToTopicResult deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
JsonNode node = jp.getCodec().readTree(jp);
boolean success = false;
String reason = null;
if (node.has("subscribed")) {
success = node.get("subscribed").asBoolean();
}
if (node.has("reason")) {
reason = node.get("reason").asText();
}
return new SubscribeToTopicResult(success, reason);
}
示例7: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public JsonUpdateWebServer deserialize(final JsonParser jp, final DeserializationContext ctxt)
throws IOException {
final ObjectCodec obj = jp.getCodec();
final JsonNode node = obj.readTree(jp).get(0);
final Set<String> groupIds = deserializeGroupIdentifiers(node);
return new JsonUpdateWebServer(node.get("webserverId").getValueAsText(),
node.get("webserverName").getTextValue(),
node.get("hostName").getTextValue(),
node.get("portNumber").getValueAsText(),
node.get("httpsPort").getValueAsText(),
groupIds,
node.get("statusPath").getTextValue(),
node.get("apacheHttpdMediaId").getTextValue());
}
示例8: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public JsonCreateWebServer deserialize(final JsonParser jp, final DeserializationContext ctxt)
throws IOException {
final ObjectCodec obj = jp.getCodec();
final JsonNode node = obj.readTree(jp).get(0);
final JsonNode apacheHttpdMediaId = node.get("apacheHttpdMediaId");
final JsonCreateWebServer jcws = new JsonCreateWebServer(node.get("webserverName").getTextValue(),
node.get("hostName").getTextValue(),
node.get("portNumber").asText(),
node.get("httpsPort").asText(),
deserializeGroupIdentifiers(node),
node.get("statusPath").getTextValue(),
apacheHttpdMediaId == null ? null : apacheHttpdMediaId.asText());
return jcws;
}
示例9: BackportedJacksonMappingIterator
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected BackportedJacksonMappingIterator(JavaType type, JsonParser jp, DeserializationContext ctxt, JsonDeserializer<?> deser) {
_type = type;
_parser = jp;
_context = ctxt;
_deserializer = (JsonDeserializer<T>) deser;
/* One more thing: if we are at START_ARRAY (but NOT root-level
* one!), advance to next token (to allow matching END_ARRAY)
*/
if (jp != null && jp.getCurrentToken() == JsonToken.START_ARRAY) {
JsonStreamContext sc = jp.getParsingContext();
// safest way to skip current token is to clear it (so we'll advance soon)
if (!sc.inRoot()) {
jp.clearCurrentToken();
}
}
}
示例10: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public Instant deserialize(final JsonParser parser, final DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
final JsonToken jsonToken = parser.getCurrentToken();
if (jsonToken == JsonToken.VALUE_NUMBER_INT)
{
return new Instant(parser.getLongValue());
}
else if (jsonToken == JsonToken.VALUE_STRING)
{
final String str = parser.getText().trim();
if (str.length() == 0)
{
return null;
}
final DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser();
final DateTime dateTime = formatter.parseDateTime(str);
return new Instant(dateTime.getMillis());
}
throw ctxt.mappingException(Instant.class);
}
示例11: addDiscoverableDeserializers
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
/**
* Search for any registered JsonDeserialize instances that have been declared using the
* ServiceLoader. Add any found to the given mapper in a 'magic' module.
*/
private static void addDiscoverableDeserializers(final ObjectMapper mapper) {
final ServiceLoader<JsonDeserializer> loader = ServiceLoader.load(JsonDeserializer.class);
final Iterator<JsonDeserializer> iterator = loader.iterator();
final SimpleModule magic = new SimpleModule("magic", new Version(1, 0, 0, ""));
while (iterator.hasNext()) {
final JsonDeserializer<?> deserializer = iterator.next();
try {
final Method deserialeMethod = deserializer.getClass()
.getDeclaredMethod("deserialize", JsonParser.class, DeserializationContext.class);
final Class<?> jsonType = deserialeMethod.getReturnType();
//noinspection unchecked
magic.addDeserializer(jsonType, (JsonDeserializer) deserializer);
}
catch(Exception e) {
throw new IllegalStateException(e);
}
}
mapper.registerModule(magic);
}
示例12: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
// validate enum class
if (enumClass == null) {
throw new JsonMappingException("Unable to parse unknown pick-list type");
}
final String listValue = jp.getText();
try {
// parse the string of the form value1;value2;...
final String[] value = listValue.split(";");
final int length = value.length;
final Object resultArray = Array.newInstance(enumClass, length);
for (int i = 0; i < length; i++) {
// use factory method to create object
Array.set(resultArray, i, factoryMethod.invoke(null, value[i].trim()));
}
return resultArray;
} catch (Exception e) {
throw new JsonParseException("Exception reading multi-select pick list value", jp.getCurrentLocation(), e);
}
}
示例13: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public NodeRef deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
JsonToken curr = jp.getCurrentToken();
if (curr == JsonToken.VALUE_STRING)
{
String nodeRefString = jp.getText();
NodeRef nodeRef = getNodeRef(nodeRefString);
return nodeRef;
}
else
{
throw new IOException("Unable to deserialize nodeRef: " + curr.asString());
}
}
示例14: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public Dpid deserialize(JsonParser jp,
DeserializationContext ctxt)
throws IOException, JsonProcessingException {
Dpid dpid = null;
jp.nextToken(); // Move to JsonToken.START_OBJECT
while (jp.nextToken() != JsonToken.END_OBJECT) {
String fieldname = jp.getCurrentName();
if ("value".equals(fieldname)) {
String value = jp.getText();
log.debug("Fieldname: {} Value: {}", fieldname, value);
dpid = new Dpid(value);
}
}
return dpid;
}
示例15: deserialize
import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public Website deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectCodec oc = jp.getCodec();
JsonNode nodes = oc.readTree(jp);
String websitePushID = nodes.get("websitePushID").getTextValue();
String websiteName = nodes.get("websiteName").getTextValue();
List<String> allowedDomains = new ArrayList<String>();
for (JsonNode node : nodes.get("allowedDomains")) {
allowedDomains.add(node.getTextValue());
}
String urlFormatString = nodes.get("urlFormatString").getTextValue();
String authenticationToken = nodes.get("authenticationToken").getTextValue();
String webServiceUrl = nodes.get("webServiceURL").getTextValue();
return new WebsiteBuilder()
.setWebsiteName(websiteName)
.setWebsitePushId(websitePushID)
.setAllowedDomains(allowedDomains)
.setUrlFormatString(urlFormatString)
.setAuthenticationToken(authenticationToken)
.setWebServiceUrl(webServiceUrl)
.build();
}