/** * <p>doDeserializeNonArray</p> * * @param reader a {@link com.github.nmorel.gwtjackson.client.stream.JsonReader} object. * @param ctx a {@link com.github.nmorel.gwtjackson.client.JsonDeserializationContext} object. * @param params a {@link com.github.nmorel.gwtjackson.client.JsonDeserializerParameters} object. * @return a T object. */ protected T doDeserializeNonArray( JsonReader reader, JsonDeserializationContext ctx, JsonDeserializerParameters params ) { if ( ctx.isAcceptSingleValueAsArray() ) { return doDeserializeSingleArray( reader, ctx, params ); } else { throw ctx.traceError( "Cannot deserialize an array out of " + reader.peek() + " token", reader ); } }
@Override protected Key<T> doDeserialize( String key, JsonDeserializationContext ctx ) { JsonReader jsonReader = ctx.newJsonReader( key ); return deserializer.deserialize( jsonReader, ctx ); } }
public final JsonDeserializationContext build() { return new JsonDeserializationContext( failOnUnknownProperties, unwrapRootValue, acceptSingleValueAsArray, wrapExceptions, useSafeEval, readUnknownEnumValuesAsNull, useBrowserTimezone ); } }
/** * Trace an error with current reader state and returns a corresponding exception. * * @param cause cause of the error * @param reader current reader * * @return a {@link JsonDeserializationException} if we wrap the exceptions, the cause otherwise */ public RuntimeException traceError( RuntimeException cause, JsonReader reader ) { RuntimeException exception = traceError( cause ); traceReaderInfo( reader ); return exception; }
private BeanPropertyDeserializer<T, ?> getPropertyDeserializer( String propertyName, JsonDeserializationContext ctx, boolean ignoreUnknown ) { BeanPropertyDeserializer<T, ?> property = deserializers.get( propertyName ); if ( null == property ) { if ( !ignoreUnknown && ctx.isFailOnUnknownProperties() && null == anySetterDeserializer ) { throw ctx.traceError( "Unknown property '" + propertyName + "'" ); } } return property; }
/** * Trace an error with current reader state and returns a corresponding exception. * * @param message error message * @param reader current reader * * @return a {@link JsonDeserializationException} with the given message */ public JsonDeserializationException traceError( String message, JsonReader reader ) { getLogger().log( Level.SEVERE, message ); traceReaderInfo( reader ); return new JsonDeserializationException( message ); }
/** {@inheritDoc} */ @Override public final Object readId( JsonReader reader, JsonDeserializationContext ctx ) { throw ctx.traceError( "readId() is not supported by PropertyIdentitySerializationInfo" ); } }
JsonReader reader = ctx.newJsonReader( in ); if ( ctx.isUnwrapRootValue() ) { throw ctx.traceError( "Unwrap root value is enabled but the input is not a JSON Object", reader ); throw ctx.traceError( "Unwrap root value is enabled but the JSON Object is empty", reader ); throw ctx.traceError( "Unwrap root value is enabled but the name '" + name + "' don't match the expected rootName " + "'" + rootName + "'", reader ); throw ctx.traceError( e, reader );
identityReader = ctx.newJsonReader( propertyValue ); } else { ctx.addObjectId( identityInfo.newIdKey( id ), bean ); throw ctx.traceError( "Required properties are missing : " + requiredPropertiesLeft, reader );
@Inject JsonSerialization(JacksonMapperProvider jacksonMapperProvider) { this.jacksonMapperProvider = jacksonMapperProvider; deserializationContext = JsonDeserializationContext.builder() .failOnUnknownProperties(false); serializationContext = JsonSerializationContext.builder(); }
id = identityInfo.readId( reader, ctx ); Object instance = ctx.getObjectWithId( identityInfo.newIdKey( id ) ); if ( null == instance ) { throw ctx.traceError( "Cannot find an object with id " + id, reader ); throw ctx.traceError( "Cannot find the property " + typeInfo .getPropertyName() + " containing the type information", reader ); throw ctx.traceError( "JsonTypeInfo.As." + typeInfo.getInclude() + " is not supported", reader ); throw ctx.traceError( "Cannot instantiate the type " + getDeserializedType().getName(), reader );
/** * Trace an error and returns a corresponding exception. * * @param cause cause of the error * * @return a {@link JsonDeserializationException} if we wrap the exceptions, the cause otherwise */ public RuntimeException traceError( RuntimeException cause ) { getLogger().log( Level.SEVERE, "Error during deserialization", cause ); if ( wrapExceptions ) { return new JsonDeserializationException( cause ); } else { return cause; } }
@Override public T deserializeInline( JsonReader reader, JsonDeserializationContext ctx, JsonDeserializerParameters params, IdentityDeserializationInfo identityInfo, TypeDeserializationInfo typeInfo, String typeInformation, Map<String, String> bufferedProperties ) { throw ctx.traceError( "Cannot deserialize into a bean when not using an AbstractBeanJsonDeserializer" ); }
/** {@inheritDoc} */ @Override public T read( String in ) throws JsonDeserializationException { return read( in, JsonDeserializationContext.builder().build() ); }
/** * Trace the current reader state */ private void traceReaderInfo( JsonReader reader ) { if ( null != reader && getLogger().isLoggable( Level.INFO ) ) { getLogger().log( Level.INFO, "Error at line " + reader.getLineNumber() + " and column " + reader .getColumnNumber() + " of input <" + reader.getInput() + ">" ); } }
/** {@inheritDoc} */ @Override protected char[] doDeserializeNonArray( JsonReader reader, JsonDeserializationContext ctx, JsonDeserializerParameters params ) { if ( JsonToken.STRING == reader.peek() ) { return reader.nextString().toCharArray(); } else if ( ctx.isAcceptSingleValueAsArray() ) { return doDeserializeSingleArray( reader, ctx, params ); } else { throw ctx.traceError( "Cannot deserialize a char[] out of " + reader.peek() + " token", reader ); } }
/** * Trace an error with current reader state and returns a corresponding exception. * * @param message error message * * @return a {@link JsonDeserializationException} with the given message */ public JsonDeserializationException traceError( String message ) { return traceError( message, null ); }
protected JsonDeserializationContext newDefaultDeserializationContext() { return JsonDeserializationContext.builder().build(); }
private void flushBufferedProperties( T bean, Map<String, String> bufferedProperties, Set<String> requiredPropertiesLeft, JsonDeserializationContext ctx, boolean ignoreUnknown, Set<String> ignoredProperties ) { if ( null != bufferedProperties && !bufferedProperties.isEmpty() ) { for ( Entry<String, String> bufferedProperty : bufferedProperties.entrySet() ) { String propertyName = bufferedProperty.getKey(); requiredPropertiesLeft.remove( propertyName ); if ( ignoredProperties.contains( propertyName ) ) { continue; } BeanPropertyDeserializer<T, ?> property = getPropertyDeserializer( propertyName, ctx, ignoreUnknown ); if ( null != property ) { property.deserialize( ctx.newJsonReader( bufferedProperty.getValue() ), bean, ctx ); } else if ( null != anySetterDeserializer ) { anySetterDeserializer.deserialize( ctx.newJsonReader( bufferedProperty.getValue() ), bean, propertyName, ctx ); } } } }
/** {@inheritDoc} */ @Override protected byte[] doDeserializeNonArray( JsonReader reader, JsonDeserializationContext ctx, JsonDeserializerParameters params ) { if ( JsonToken.STRING == reader.peek() ) { return Base64Utils.fromBase64( reader.nextString() ); } else if ( ctx.isAcceptSingleValueAsArray() ) { return doDeserializeSingleArray( reader, ctx, params ); } else { throw ctx.traceError( "Cannot deserialize a byte[] out of " + reader.peek() + " token", reader ); } }