当前位置: 首页>>代码示例>>Java>>正文


Java JsonTokenId类代码示例

本文整理汇总了Java中com.fasterxml.jackson.core.JsonTokenId的典型用法代码示例。如果您正苦于以下问题:Java JsonTokenId类的具体用法?Java JsonTokenId怎么用?Java JsonTokenId使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JsonTokenId类属于com.fasterxml.jackson.core包,在下文中一共展示了JsonTokenId类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeValue

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
private void writeValue(JsonRecord value) throws IOException {
    switch (value.getKind()) {
        case JsonTokenId.ID_STRING:
            jg.writeString(value.getValue());
            break;
        case JsonTokenId.ID_NULL:
            jg.writeNull();
            break;
        case JsonTokenId.ID_NUMBER_FLOAT:
        case JsonTokenId.ID_NUMBER_INT:
            jg.writeNumber(value.getValue());
            break;
        case JsonTokenId.ID_TRUE:
            jg.writeBoolean(true);
            break;
        case JsonTokenId.ID_FALSE:
            jg.writeBoolean(false);
            break;
        default:
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:22,代码来源:JsonRecordConsumer.java

示例2: deserialize

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
@Override
public LocalDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException
{
    if (parser.hasTokenId(JsonTokenId.ID_STRING)) {
        String string = parser.getText().trim();
        if (string.length() == 0) {
            return null;
        }
        
        try {
            return LocalDateTime.parse(string, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        } catch (DateTimeException e) {
            throw new IOException(e);
        }
    }
    if (parser.hasTokenId(JsonTokenId.ID_EMBEDDED_OBJECT)) {
        return (LocalDateTime) parser.getEmbeddedObject();
    }
    throw context.wrongTokenException(parser, JsonToken.VALUE_STRING, "Expected string.");
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:21,代码来源:LocalDateTimeDeserializer.java

示例3: deserialize

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
@Override
public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException
{
    if (parser.hasTokenId(JsonTokenId.ID_STRING)) {
        String string = parser.getText().trim();
        if (string.length() == 0) {
            return null;
        }
        
        try {
            return LocalDate.parse(string, DateTimeFormatter.ISO_LOCAL_DATE);
        } catch (DateTimeException e) {
            throw new IOException(e);
        }
    }
    if (parser.hasTokenId(JsonTokenId.ID_EMBEDDED_OBJECT)) {
        return (LocalDate) parser.getEmbeddedObject();
    }
    throw context.wrongTokenException(parser, JsonToken.VALUE_STRING, "Expected string.");
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:21,代码来源:LocalDateDeserializer.java

示例4: deserialize

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
@Override
public Duration deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    switch (parser.getCurrentTokenId()) {
        case JsonTokenId.ID_NUMBER_FLOAT:
            BigDecimal value = parser.getDecimalValue();
            long seconds = value.longValue();
            int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
            return Duration.ofSeconds(seconds, nanoseconds);

        case JsonTokenId.ID_NUMBER_INT:
            return Duration.ofSeconds(parser.getLongValue());

        case JsonTokenId.ID_STRING:
            String string = parser.getText().trim();
            if (string.length() == 0) {
                return null;
            }
            return Duration.parse(string);
    }
    throw context.mappingException("Expected type float, integer, or string.");
}
 
开发者ID:bootique,项目名称:bootique,代码行数:22,代码来源:DurationDeserializer.java

示例5: deserializeObject

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
private Cookies deserializeObject(JsonParser p, DeserializationContext ctxt, JsonNodeFactory nodeFactory) throws IOException {
    Cookies cookies = new Cookies();
    NottableString key = string("");
    while (true) {
        JsonToken t = p.nextToken();
        switch (t.id()) {
            case JsonTokenId.ID_FIELD_NAME:
                key = string(ctxt.readValue(p, String.class));
                break;
            case JsonTokenId.ID_STRING:
                cookies.withEntry(key, string(ctxt.readValue(p, String.class)));
                break;
            case JsonTokenId.ID_END_OBJECT:
                return cookies;
            default:
                throw new RuntimeException("Unexpected token: \"" + t + "\" id: \"" + t.id() + "\" text: \"" + p.getText());
        }
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:20,代码来源:CookiesDeserializer.java

示例6: processToken

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
private JsonToken processToken(JsonToken curToken, JsonParser parser, JsonGenerator jgen)
    throws IOException {
  if (curToken.isStructEnd()) {
    // this is our escape and base case.
    return curToken;
  }
  if (curToken.isStructStart()) {
    processStructStart(curToken, jgen);
    JsonToken token = processToken(parser.nextToken(), parser, jgen);
    while (!token.isStructEnd()) {
      token = processToken(token, parser, jgen);
    }
    processStructEnd(token, jgen);
    return parser.nextToken();
  }

  if (curToken.id() == JsonTokenId.ID_FIELD_NAME) {
    String currentName = parser.getCurrentName();
    if (isFiltered && filters.containsKey(parser.getCurrentName())) {
      jgen.writeFieldName(currentName);
      // perform filtering.
      return filters.get(parser.getCurrentName()).processToken(parser.nextToken(), parser, jgen);
    } else if (!isFiltered) {
      jgen.writeFieldName(currentName);
      return processToken(parser.nextToken(), parser, jgen);
    } else {
      parser.nextToken();
      parser.skipChildren();
      return processToken(parser.nextToken(), parser, jgen);
    }
  } else if (curToken.isScalarValue()) {
    processValue(curToken, parser, jgen);
    return parser.nextToken();
  } else {
    LOGGER.error(
        "Unable to process the token {} with name {}.", curToken, parser.getCurrentName());
    throw new RuntimeException(
        "Unable to process the token " + curToken + " with name" + parser.getCurrentName());
  }
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:41,代码来源:FieldFilter.java

示例7: processValue

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
/**
 * Uses a JsonToken + JsonParser to determine how to write a value to the JsonGenerator.
 *
 * <p>This separation exists so we can separate the iteration logic from the parsing logic.
 *
 * @param valueToken current token we are interested in from the parser
 * @param parser current parser
 * @param jgen JsonGenerator that is used for writing json onto an underlying stream
 * @throws JsonGenerationException if access to the JsonParser throws a JsonGenerationException
 * @throws IOException if the Jackson utilties (JsonParser or JsonGenerator) throw an IOException
 */
private void processValue(JsonToken valueToken, JsonParser parser, JsonGenerator jgen)
    throws IOException {
  if (valueToken.isBoolean()) {
    jgen.writeBoolean(parser.getBooleanValue());
  } else if (valueToken.isNumeric()) {
    if (parser.getNumberType() == JsonParser.NumberType.INT) {
      jgen.writeNumber(parser.getIntValue());
    } else if (parser.getNumberType() == JsonParser.NumberType.DOUBLE) {
      jgen.writeNumber(parser.getDoubleValue());
    } else if (parser.getNumberType() == JsonParser.NumberType.FLOAT) {
      jgen.writeNumber(parser.getFloatValue());
    } else if (parser.getNumberType() == JsonParser.NumberType.LONG) {
      jgen.writeNumber(parser.getLongValue());
    } else if (parser.getNumberType() == JsonParser.NumberType.BIG_DECIMAL) {
      jgen.writeNumber(parser.getDecimalValue());
    } else if (parser.getNumberType() == JsonParser.NumberType.BIG_INTEGER) {
      jgen.writeNumber(parser.getBigIntegerValue());
    } else {
      LOGGER.error("Found unsupported numeric value with name {}.", parser.getCurrentName());
      throw new RuntimeException(
          "Found unsupported numeric value with name " + parser.getCurrentName());
    }
  } else if (valueToken.id() == JsonTokenId.ID_STRING) {
    jgen.writeString(parser.getText());
  } else {
    // Something bad just happened. Probably an unsupported type.
    LOGGER.error(
        "Found unsupported value type {} for name {}.", valueToken.id(), parser.getCurrentName());
    throw new RuntimeException(
        "Found unsupported value type " + valueToken.id() + " for name " + parser
            .getCurrentName());
  }
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:45,代码来源:FieldFilter.java

示例8: processStructEnd

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
private void processStructEnd(JsonToken token, JsonGenerator jgen)
    throws IOException {
  if (token.id() == JsonTokenId.ID_END_OBJECT) {
    jgen.writeEndObject();
  } else if (token.id() == JsonTokenId.ID_END_ARRAY) {
    jgen.writeEndArray();
  } else {
    LOGGER.error("Illegal struct end {}", token.id());
    throw new RuntimeException("Illegal struct end " + token.id());
  }
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:12,代码来源:FieldFilter.java

示例9: deserialize

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
public LocalDate deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException {

        if (parser.hasTokenId(JsonTokenId.ID_STRING)) {
            String date = parser.getText().trim();

            if (date.isEmpty()) {
                return null;
            }

            return LocalDateTime.ofInstant(Instant.parse(date), ZoneOffset.UTC).toLocalDate();
        }

        return null;
    }
 
开发者ID:jaxio,项目名称:celerio-angular-quickstart,代码行数:15,代码来源:CustomLocalDateDeserializer.java

示例10: deserialize

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
@Override
public Duration deserialize(JsonParser parser, DeserializationContext context) throws IOException
{
    switch (parser.currentTokenId())
    {
        case JsonTokenId.ID_NUMBER_FLOAT:
            BigDecimal value = parser.getDecimalValue();
            long seconds = value.longValue();
            int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
            return Duration.ofSeconds(seconds, nanoseconds);

        case JsonTokenId.ID_NUMBER_INT:
            if(context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)) {
                return Duration.ofSeconds(parser.getLongValue());
            }
            return Duration.ofMillis(parser.getLongValue());

        case JsonTokenId.ID_STRING:
            String string = parser.getText().trim();
            if (string.length() == 0) {
                return null;
            }
            try {
                return Duration.parse(string);
            } catch (DateTimeException e) {
                return _rethrowDateTimeException(parser, context, e, string);
            }
        case JsonTokenId.ID_EMBEDDED_OBJECT:
            // 20-Apr-2016, tatu: Related to [databind#1208], can try supporting embedded
            //    values quite easily
            return (Duration) parser.getEmbeddedObject();
            
        case JsonTokenId.ID_START_ARRAY:
        	return _deserializeFromArray(parser, context);
    }
    return _reportWrongToken(parser, context, JsonToken.VALUE_STRING,
            JsonToken.VALUE_NUMBER_INT, JsonToken.VALUE_NUMBER_FLOAT);
}
 
开发者ID:FasterXML,项目名称:jackson-modules-java8,代码行数:39,代码来源:DurationDeserializer.java

示例11: deserializeArray

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
private Cookies deserializeArray(JsonParser p, DeserializationContext ctxt, JsonNodeFactory nodeFactory) throws IOException {
    Cookies headers = new Cookies();
    NottableString key = null;
    NottableString value = null;
    String fieldName = null;
    while (true) {
        JsonToken t = p.nextToken();
        switch (t.id()) {
            case JsonTokenId.ID_END_ARRAY:
                return headers;
            case JsonTokenId.ID_START_OBJECT:
                key = null;
                value = null;
                break;
            case JsonTokenId.ID_FIELD_NAME:
                fieldName = ctxt.readValue(p, String.class);
                break;
            case JsonTokenId.ID_STRING:
                if ("name".equals(fieldName)) {
                    key = string(ctxt.readValue(p, String.class));
                } else if ("value".equals(fieldName)) {
                    value = string(ctxt.readValue(p, String.class));
                }
                break;
            case JsonTokenId.ID_END_OBJECT:
                headers.withEntry(key, value);
                break;
            default:
                throw new RuntimeException("Unexpected token: \"" + t + "\" id: \"" + t.id() + "\" text: \"" + p.getText());
        }
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:33,代码来源:CookiesDeserializer.java

示例12: getCurrentTokenId

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
@Override
public int getCurrentTokenId() {
    return currentToken == null
           ? JsonTokenId.ID_NO_TOKEN
           : currentToken.id();
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:7,代码来源:IonParser.java

示例13: getCurrentTokenId

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
@Override
public int getCurrentTokenId() {
    return currentToken == null
            ? JsonTokenId.ID_NO_TOKEN
            : currentToken.id();
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:7,代码来源:IonParser.java

示例14: deserialize

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
@Override
public LocalDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    if (parser.hasTokenId(JsonTokenId.ID_STRING)) {
        String string = parser.getText().trim();
        if (string.length() == 0) {
            return null;
        }
        return LocalDateTime.parse(string, _formatter);
    }
    if (parser.isExpectedStartArrayToken()) {
        if (parser.nextToken() == JsonToken.END_ARRAY) {
            return null;
        }
        int year = parser.getIntValue();

        parser.nextToken();
        int month = parser.getIntValue();

        parser.nextToken();
        int day = parser.getIntValue();

        parser.nextToken();
        int hour = parser.getIntValue();

        parser.nextToken();
        int minute = parser.getIntValue();

        if (parser.nextToken() != JsonToken.END_ARRAY) {
            int second = parser.getIntValue();

            if (parser.nextToken() != JsonToken.END_ARRAY) {
                int partialSecond = parser.getIntValue();

                if (parser.nextToken() != JsonToken.END_ARRAY) {
                    throw context.wrongTokenException(parser, JsonToken.END_ARRAY, "Expected array to end.");
                }
                return LocalDateTime.of(year, month, day, hour, minute, second, partialSecond);
            }
            return LocalDateTime.of(year, month, day, hour, minute, second);
        }
        return LocalDateTime.of(year, month, day, hour, minute);
    }
    throw context.wrongTokenException(parser, JsonToken.START_ARRAY, "Expected array or string.");
}
 
开发者ID:bootique,项目名称:bootique,代码行数:45,代码来源:LocalDateTimeDeserializer.java

示例15: deserializeFromObject

import com.fasterxml.jackson.core.JsonTokenId; //导入依赖的package包/类
@Override
public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) throws IOException {
    if (_nonStandardCreation || _needViewProcesing) {
        return super.deserializeFromObject(p, ctxt);
    }

    Object bean = null;

    if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) {
        String propertyName = p.getCurrentName();
        do {
            p.nextToken();
            SettableBeanProperty property = _beanProperties.find(propertyName);

            if (property == null) {
                handleUnknownVanilla(p, ctxt, bean, propertyName);
                continue;
            }

            // lazily create the bean, the id property must be the first property
            if (bean == null) {
                if (propertyName.equals(_objectIdReader.propertyName.getSimpleName())) {

                    // deserialize id
                    Object id = property.deserialize(p, ctxt);

                    ReadableObjectId objectId = ctxt.findObjectId(id,
                            _objectIdReader.generator, _objectIdReader.resolver);

                    bean = objectId == null ? null : objectId.resolve();
                    if (bean == null) {
                        bean = _valueInstantiator.createUsingDefault(ctxt);
                        property.set(bean, id);
                    }
                } else {
                    bean = _valueInstantiator.createUsingDefault(ctxt);
                }
                p.setCurrentValue(bean);
            }
            property.deserializeAndSet(p, ctxt, bean);

        } while ((propertyName = p.nextFieldName()) != null);
    }

    return bean;
}
 
开发者ID:requery,项目名称:requery,代码行数:47,代码来源:EntityBeanDeserializer.java


注:本文中的com.fasterxml.jackson.core.JsonTokenId类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。