當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonbException類代碼示例

本文整理匯總了Java中javax.json.bind.JsonbException的典型用法代碼示例。如果您正苦於以下問題:Java JsonbException類的具體用法?Java JsonbException怎麽用?Java JsonbException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonbException類屬於javax.json.bind包,在下文中一共展示了JsonbException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: marshall

import javax.json.bind.JsonbException; //導入依賴的package包/類
/**
 * Marshals given object to provided Writer or OutputStream.
 *
 * @param object object to marshall
 * @param jsonGenerator generator to use
 */
public void marshall(Object object, JsonGenerator jsonGenerator) {
    try {
        final ContainerModel model = new ContainerModel(runtimeType != null ? runtimeType : object.getClass(), null);
        serializeRoot(object, jsonGenerator, model);
    } catch (JsonbException e) {
        logger.severe(e.getMessage());
        throw e;
    } finally {
        try {
            jsonGenerator.close();
        } catch (JsonGenerationException jge) {
            logger.severe(jge.getMessage());
        }
    }
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:22,代碼來源:Marshaller.java

示例2: createJsonpProperties

import javax.json.bind.JsonbException; //導入依賴的package包/類
/**
 * Propagates properties from JsonbConfig to JSONP generator / parser factories.
 *
 * @param jsonbConfig jsonb config
 * @return properties for JSONP generator / parser
 */
protected Map<String, ?> createJsonpProperties(JsonbConfig jsonbConfig) {
    //JSONP 1.0 actually ignores the value, just checks the key is present. Only set if JsonbConfig.FORMATTING is true.
    final Optional<Object> property = jsonbConfig.getProperty(JsonbConfig.FORMATTING);
    final Map<String, Object> factoryProperties = new HashMap<>();
    if (property.isPresent()) {
        final Object value = property.get();
        if (!(value instanceof Boolean)) {
            throw new JsonbException(Messages.getMessage(MessageKeys.JSONB_CONFIG_FORMATTING_ILLEGAL_VALUE));
        }
        if ((Boolean) value) {
            factoryProperties.put(JsonGenerator.PRETTY_PRINTING, Boolean.TRUE);
        }
        return factoryProperties;
    }
    return factoryProperties;
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:23,代碼來源:JsonBinding.java

示例3: acceptMethod

import javax.json.bind.JsonbException; //導入依賴的package包/類
@Override
protected void acceptMethod(Method method, OperationMode mode) {
    try {
        switch (mode) {
            case GET:
                getHandle = MethodHandles.lookup().unreflect(method);
                break;
            case SET:
                setHandle = MethodHandles.lookup().unreflect(method);
                break;
            default:
                throw new IllegalStateException("Unknown mode");
        }
    } catch (IllegalAccessException e) {
        throw new JsonbException(Messages.getMessage(MessageKeys.CREATING_HANDLES), e);
    }
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:18,代碼來源:MethodHandleValuePropagation.java

示例4: acceptField

import javax.json.bind.JsonbException; //導入依賴的package包/類
@Override
protected void acceptField(Field field, OperationMode mode) {
    try {
        switch (mode) {
            case GET:
                getHandle = MethodHandles.lookup().unreflectGetter(field);
                break;
            case SET:
                setHandle = MethodHandles.lookup().unreflectSetter(field);
                break;
            default:
                throw new IllegalStateException("Unknown mode");
        }
    } catch (IllegalAccessException e) {
        throw new JsonbException(Messages.getMessage(MessageKeys.CREATING_HANDLES), e);
    }
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:18,代碼來源:MethodHandleValuePropagation.java

示例5: getInterfaceMappedType

import javax.json.bind.JsonbException; //導入依賴的package包/類
private Class<?> getInterfaceMappedType(Class<?> interfaceType) {
    if (interfaceType.isInterface()) {
        Class implementationClass = null;
        //annotation
        if (getModel().getCustomization() instanceof PropertyCustomization) {
             implementationClass = ((PropertyCustomization) getModel().getCustomization()).getImplementationClass();
        }
        //JsonbConfig
        if (implementationClass == null) {
            implementationClass = jsonbContext.getConfigProperties().getUserTypeMapping().get(interfaceType);
        }
        if (implementationClass != null) {
            if (!interfaceType.isAssignableFrom(implementationClass)) {
                throw new JsonbException(Messages.getMessage(MessageKeys.IMPL_CLASS_INCOMPATIBLE, implementationClass, interfaceType));
            }
            return implementationClass;
        }
    }
    return null;
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:21,代碼來源:DeserializerBuilder.java

示例6: deserialize

import javax.json.bind.JsonbException; //導入依賴的package包/類
@Override
protected Double deserialize(String jsonValue, Unmarshaller unmarshaller, Type rtType) {
    switch (jsonValue) {
        case NAN:
            return Double.NaN;
        case POSITIVE_INFINITY:
            return Double.POSITIVE_INFINITY;
        case NEGATIVE_INFINITY:
            return Double.NEGATIVE_INFINITY;
    }
    return deserializeFormatted(jsonValue, false, unmarshaller.getJsonbContext())
            .map(num -> Double.parseDouble(num.toString()))
            .orElseGet(() -> {
                try {
                    return Double.parseDouble(jsonValue);
                } catch (NumberFormatException e) {
                    throw new JsonbException(Messages.getMessage(MessageKeys.DESERIALIZE_VALUE_ERROR,
                            Double.class));
                }
            });
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:22,代碼來源:DoubleTypeDeserializer.java

示例7: deserializeInternal

import javax.json.bind.JsonbException; //導入依賴的package包/類
protected void deserializeInternal(JsonbParser parser, Unmarshaller context) {
    parserContext = moveToFirst(parser);
    while (parser.hasNext()) {
        final JsonParser.Event event = parser.next();
        switch (event) {
            case START_OBJECT:
            case START_ARRAY:
            case VALUE_STRING:
            case VALUE_NUMBER:
            case VALUE_FALSE:
            case VALUE_TRUE:
                deserializeNext(parser, context);
                break;
            case KEY_NAME:
                break;
            case VALUE_NULL:
                appendResult(null);
                break;
            case END_OBJECT:
            case END_ARRAY:
                return;
            default:
                throw new JsonbException(Messages.getMessage(MessageKeys.NOT_VALUE_TYPE, event));
        }
    }
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:27,代碼來源:AbstractContainerDeserializer.java

示例8: deserializeFormatted

import javax.json.bind.JsonbException; //導入依賴的package包/類
protected final Optional<Number> deserializeFormatted(String jsonValue, boolean integerOnly, JsonbContext jsonbContext) {
    if (getModel() == null || getModel().getCustomization() == null
            || getModel().getCustomization().getDeserializeNumberFormatter() == null) {
        return Optional.empty();
    }

    final JsonbNumberFormatter numberFormat = getModel().getCustomization().getDeserializeNumberFormatter();
    //consider synchronizing on format instance or per thread cache.
    final NumberFormat format = NumberFormat.getInstance(jsonbContext.getConfigProperties().getLocale(numberFormat.getLocale()));
    ((DecimalFormat)format).applyPattern(numberFormat.getFormat());
    format.setParseIntegerOnly(integerOnly);
    try {
        return Optional.of(format.parse(jsonValue));
    } catch (ParseException e) {
        throw new JsonbException(Messages.getMessage(MessageKeys.PARSING_NUMBER, jsonValue, numberFormat.getFormat()));
    }
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:18,代碼來源:AbstractNumberDeserializer.java

示例9: deserialize

import javax.json.bind.JsonbException; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public T deserialize(JsonParser parser, DeserializationContext context, Type rtType) {
    Unmarshaller unmarshaller = (Unmarshaller) context;
    unmarshaller.setCurrent(this);
    try {
        unmarshaller.getJsonbContext().addProcessedType(adapterInfo.getBindingType());
        final A result =  adaptedTypeDeserializer.deserialize(parser, context, rtType);
        final T adapted = ((JsonbAdapter<T, A>) adapterInfo.getAdapter()).adaptFromJson(result);
        unmarshaller.setCurrent(wrapperItem);
        return adapted;
    } catch (Exception e) {
        throw new JsonbException(Messages.getMessage(MessageKeys.ADAPTER_EXCEPTION, adapterInfo.getBindingType(), adapterInfo.getToType(), adapterInfo.getAdapter().getClass()), e);
    } finally {
        unmarshaller.getJsonbContext().removeProcessedType(adapterInfo.getBindingType());
    }
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:18,代碼來源:AdaptedObjectDeserializer.java

示例10: deserialize

import javax.json.bind.JsonbException; //導入依賴的package包/類
@Override
public JsonValue deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    final JsonParser.Event next = ((JsonbRiParser)parser).getLastEvent();
    switch (next) {
        case VALUE_TRUE:
            return JsonValue.TRUE;
        case VALUE_FALSE:
            return JsonValue.FALSE;
        case VALUE_NULL:
            return JsonValue.NULL;
        case VALUE_STRING:
        case VALUE_NUMBER:
            return parser.getValue();
        default:
            throw new JsonbException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Unknown JSON value: "+next));
    }
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:18,代碼來源:JsonValueDeserializer.java

示例11: deserialize

import javax.json.bind.JsonbException; //導入依賴的package包/類
@Override
public T deserialize(String jsonValue, Unmarshaller unmarshaller, Type rtType) {
    final JsonbDateFormatter formatter = getJsonbDateFormatter(unmarshaller.getJsonbContext());
    if (JsonbDateFormat.TIME_IN_MILLIS.equals(formatter.getFormat())) {
        return fromInstant(Instant.ofEpochMilli(Long.parseLong(jsonValue)));
    } else if (formatter.getDateTimeFormatter() != null) {
        return parseWithFormatterInternal(jsonValue, formatter.getDateTimeFormatter());
    } else {
        DateTimeFormatter configDateTimeFormatter = unmarshaller.getJsonbContext().getConfigProperties().getConfigDateFormatter().getDateTimeFormatter();
        if (configDateTimeFormatter != null) {
            return parseWithFormatterInternal(jsonValue, configDateTimeFormatter);
        }
    }
    final boolean strictIJson = unmarshaller.getJsonbContext().getConfigProperties().isStrictIJson();
    if (strictIJson) {
        return parseWithFormatterInternal(jsonValue, JsonbDateFormatter.IJSON_DATE_FORMATTER);
    }
    try {
        return parseDefault(jsonValue, unmarshaller.getJsonbContext().getConfigProperties().getLocale(formatter.getLocale()));
    } catch (DateTimeParseException e) {
        throw new JsonbException(Messages.getMessage(MessageKeys.DATE_PARSE_ERROR, jsonValue), e);
    }
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:24,代碼來源:AbstractDateTimeDeserializer.java

示例12: createJsonbCreator

import javax.json.bind.JsonbException; //導入依賴的package包/類
private JsonbCreator createJsonbCreator(Executable executable, JsonbCreator existing, Class<?> clazz) {
    if (existing != null) {
        throw new JsonbException(Messages.getMessage(MessageKeys.MULTIPLE_JSONB_CREATORS, clazz));
    }

    final Parameter[] parameters = executable.getParameters();

    CreatorModel[] creatorModels = new CreatorModel[parameters.length];
    for (int i=0; i<parameters.length; i++) {
        final Parameter parameter = parameters[i];
        final JsonbProperty jsonbPropertyAnnotation = parameter.getAnnotation(JsonbProperty.class);
        if (jsonbPropertyAnnotation != null && !jsonbPropertyAnnotation.value().isEmpty()) {
            creatorModels[i] = new CreatorModel(jsonbPropertyAnnotation.value(), parameter, jsonbContext);
        } else {
            creatorModels[i] = new CreatorModel(parameter.getName(), parameter, jsonbContext);
        }
    }

    return new JsonbCreator(executable, creatorModels);
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:21,代碼來源:AnnotationIntrospector.java

示例13: checkPropertyNameClash

import javax.json.bind.JsonbException; //導入依賴的package包/類
private void checkPropertyNameClash(List<PropertyModel> collectedProperties, Class cls) {
    final List<PropertyModel> checkedProperties = new ArrayList<>();
    for (PropertyModel collectedPropertyModel : collectedProperties) {
        for (PropertyModel checkedPropertyModel : checkedProperties) {

            if ((checkedPropertyModel.getReadName().equals(collectedPropertyModel.getReadName())
            && checkedPropertyModel.isReadable() && collectedPropertyModel.isReadable()) ||
                    (checkedPropertyModel.getWriteName().equals(collectedPropertyModel.getWriteName()))
                    && checkedPropertyModel.isWritable() && collectedPropertyModel.isWritable()) {
                throw new JsonbException(Messages.getMessage(MessageKeys.PROPERTY_NAME_CLASH,
                        checkedPropertyModel.getPropertyName(), collectedPropertyModel.getPropertyName(),
                        cls.getName()));
            }
        }
        checkedProperties.add(collectedPropertyModel);
    }
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:18,代碼來源:ClassParser.java

示例14: initOrderStrategy

import javax.json.bind.JsonbException; //導入依賴的package包/類
private PropOrderStrategy initOrderStrategy() {
    final Optional<Object> property = jsonbConfig.getProperty(JsonbConfig.PROPERTY_ORDER_STRATEGY);
    if (property.isPresent()) {
        final Object strategy = property.get();
        if (!(strategy instanceof String)) {
            throw new JsonbException(Messages.getMessage(MessageKeys.PROPERTY_ORDER, strategy));
        }
        switch ((String) strategy) {
            case PropertyOrderStrategy.LEXICOGRAPHICAL:
                return new LexicographicalOrderStrategy();
            case PropertyOrderStrategy.REVERSE:
                return new ReverseOrderStrategy();
            case PropertyOrderStrategy.ANY:
                return new AnyOrderStrategy();
            default:
                throw new JsonbException(Messages.getMessage(MessageKeys.PROPERTY_ORDER, strategy));
        }
    }
    //default by spec
    return new LexicographicalOrderStrategy();
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:22,代碼來源:JsonbConfigProperties.java

示例15: initPropertyNamingStrategy

import javax.json.bind.JsonbException; //導入依賴的package包/類
private PropertyNamingStrategy initPropertyNamingStrategy() {
    final Optional<Object> property = jsonbConfig.getProperty(JsonbConfig.PROPERTY_NAMING_STRATEGY);
    if (!property.isPresent()) {
        return new IdentityStrategy();
    }
    Object propertyNamingStrategy = property.get();
    if (propertyNamingStrategy instanceof String) {
        String namingStrategyName = (String) propertyNamingStrategy;
        final PropertyNamingStrategy foundNamingStrategy = DefaultNamingStrategies.getStrategy(namingStrategyName);
        if (foundNamingStrategy == null) {
            throw new JsonbException("No property naming strategy was found for: " + namingStrategyName);
        }
        return foundNamingStrategy;
    }
    if (!(propertyNamingStrategy instanceof PropertyNamingStrategy)) {
        throw new JsonbException(Messages.getMessage(MessageKeys.PROPERTY_NAMING_STRATEGY_INVALID));
    }
    return (PropertyNamingStrategy) property.get();
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:20,代碼來源:JsonbConfigProperties.java


注:本文中的javax.json.bind.JsonbException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。