/** * Will advance to next token and bind the JSON to provided instance * * @param manifest type to read into * @param instance instance to bind * @param <T> type * @return bound instance * @throws IOException unable to process JSON */ @SuppressWarnings("unchecked") @Nullable public final <T> T next(final Class<T> manifest, final T instance) throws IOException { if (manifest == null) throw new IllegalArgumentException("manifest can't be null"); if (instance == null) throw new IllegalArgumentException("instance can't be null"); if (typeLookup == null) throw new IllegalArgumentException("typeLookup is not defined for this JsonReader. Unable to lookup specified type " + manifest); if (this.getNextToken() == 'n') { return (T)readNull(manifest); } final BindObject<T> binder = typeLookup.tryFindBinder(manifest); if (binder == null) throw new IllegalArgumentException("Binder not found for " + manifest + ". Check if binder was registered"); return binder.bind(this, instance); }
throw new IOException("Null value found for property " + ri.name + " " + reader.positionDescription()); ri.value.bind(reader, instance); currentMandatory = currentMandatory & ri.mandatoryValue; processed = true; throw new IOException("Null value found for property " + ri.name + " " + reader.positionDescription()); ri.value.bind(reader, instance); currentMandatory = currentMandatory & ri.mandatoryValue; processed = true;
private void bindContent(final JsonReader reader, final B instance) throws IOException { if (reader.last() == '}') { if (hasMandatory) { DecodePropertyInfo.showMandatoryError(reader, mandatoryFlag, decoders); } return; } long currentMandatory = mandatoryFlag; int i = 0; while(i < decoders.length) { final DecodePropertyInfo<JsonReader.BindObject> ri = decoders[i++]; final int weakHash = reader.fillNameWeakHash(); if (weakHash != ri.weakHash || !reader.wasLastName(ri.nameBytes)) { bindObjectSlow(reader, instance, currentMandatory); return; } reader.getNextToken(); if (ri.nonNull && reader.wasNull()) { throw new IOException("Null value found for property " + ri.name + " " + reader.positionDescription()); } ri.value.bind(reader, instance); currentMandatory = currentMandatory & ri.mandatoryValue; if (reader.getNextToken() == ',' && i != decoders.length) reader.getNextToken(); else break; } finalChecks(reader, instance, currentMandatory); }
/** * Will advance to next token and bind the JSON to provided instance * * @param binder binder to use * @param instance instance to bind * @param <T> type * @return bound instance * @throws IOException unable to process JSON */ @SuppressWarnings("unchecked") @Nullable public final <T> T next(final BindObject<T> binder, final T instance) throws IOException { if (binder == null) throw new IllegalArgumentException("binder can't be null"); if (instance == null) throw new IllegalArgumentException("instance can't be null"); if (this.getNextToken() == 'n') { if (!wasNull()) throw new IllegalArgumentException("Invalid JSON detected " + positionDescription()); return null; } return binder.bind(this, instance); }
public T bind(final JsonReader reader, final T instance) throws IOException { if (reader.last() == '{') { if (objectFormat == null) throw new IOException("Object format for " + manifest.getTypeName() + " is not defined"); if (objectBinder == null) throw new IOException(manifest.getTypeName() + " does not support binding"); return objectBinder.bind(reader, instance); } else if (reader.last() == '[') { if (arrayFormat == null) throw new IOException("Array format for " + manifest.getTypeName() + " is not defined"); if (arrayBinder == null) throw new IOException(manifest.getTypeName() + " does not support binding"); return arrayBinder.bind(reader, instance); } else if (objectFormat != null && arrayFormat != null) { throw new IOException("Expecting '{' or '[' " + reader.positionDescription() + " for decoding " + manifest.getTypeName() + ". Found " + (char) reader.last()); } else if (objectFormat != null) { throw new IOException("Expecting '{' " + reader.positionDescription() + " for decoding " + manifest.getTypeName() + ". Found " + (char) reader.last()); } else { throw new IOException("Expecting '[' " + reader.positionDescription() + " for decoding " + manifest.getTypeName() + ". Found " + (char) reader.last()); } } }
private void bindContent(final JsonReader reader, final B instance) throws IOException { int i = 0; while (i < decoders.length) { decoders[i].bind(reader, instance); i++; if (reader.getNextToken() == ',') reader.getNextToken(); else break; } if (i != decoders.length) { throw new IOException("Expecting to read " + decoders.length + " elements in the array while decoding " + manifest.getTypeName() + ". Read only: " + i + " at position: " + reader.positionInStream()); } if (reader.last() != ']') { throw new IOException("Expecting ']' " + reader.positionDescription() + " while decoding " + manifest.getTypeName() + ". Found " + (char) reader.last()); } } }
@Override public Object bind(final JsonReader reader, final Object instance) throws IOException { if (resolvedBinder == null) { if (checkSignatureNotFound()) { final JsonReader.BindObject tmp = json.tryFindBinder(type); if (tmp == null || tmp == this) { throw new SerializationException("Unable to find binder for " + type); } resolvedBinder = tmp; } } return resolvedBinder.bind(reader, instance); }