Java Code Examples for com.dslplatform.json.JsonReader#ReadObject
The following examples show how to use
com.dslplatform.json.JsonReader#ReadObject .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImmutableDescription.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 6 votes |
ImmutableDescription( final Type manifest, final Object[] defArgs, final Settings.Function<Object[], T> newInstance, final JsonWriter.WriteObject[] encoders, final DecodePropertyInfo<JsonReader.ReadObject>[] decoders, final boolean alwaysSerialize, final boolean skipOnUnknown) { super(encoders, alwaysSerialize); if (manifest == null) throw new IllegalArgumentException("manifest can't be null"); if (defArgs == null) throw new IllegalArgumentException("defArgs can't be null"); if (newInstance == null) throw new IllegalArgumentException("create can't be null"); if (decoders == null) throw new IllegalArgumentException("decoders can't be null"); this.manifest = manifest; this.defArgs = defArgs; this.newInstance = newInstance; this.decoders = DecodePropertyInfo.prepare(decoders); this.skipOnUnknown = skipOnUnknown; this.mandatoryFlag = DecodePropertyInfo.calculateMandatory(this.decoders); hasMandatory = mandatoryFlag != 0; this.startError = String.format("Expecting '{' to start decoding %s", Reflection.typeDescription(manifest)); this.endError = String.format("Expecting '}' or ',' while decoding %s", Reflection.typeDescription(manifest)); }
Example 2
Source File: OptionalAnalyzer.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Nullable private static OptionalDecoder analyzeDecoding(final Type manifest, final Type content, final Class<?> raw, final DslJson json) { if (raw != Optional.class) { return null; } else if (content == Optional.class) { final OptionalDecoder nested = analyzeDecoding(content, Object.class, Optional.class, json); final OptionalDecoder outer = new OptionalDecoder<>(nested); json.registerReader(manifest, outer); return outer; } final JsonReader.ReadObject<?> reader = json.tryFindReader(content); if (reader == null) { return null; } final OptionalDecoder decoder = new OptionalDecoder<>(reader); json.registerReader(manifest, decoder); return decoder; }
Example 3
Source File: ImmutableDescription.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 5 votes |
public ImmutableDescription( final Class<T> manifest, final Object[] defArgs, final Settings.Function<Object[], T> newInstance, final JsonWriter.WriteObject[] encoders, final DecodePropertyInfo<JsonReader.ReadObject>[] decoders, final boolean alwaysSerialize, final boolean skipOnUnknown) { this((Type) manifest, defArgs, newInstance, encoders, decoders, alwaysSerialize, skipOnUnknown); }
Example 4
Source File: ImmutableDescription.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Nullable public T read(final JsonReader reader) throws IOException { if (reader.wasNull()) return null; else if (reader.last() != '{') { throw reader.newParseError(startError); } if (reader.getNextToken() == '}') { if (hasMandatory) { DecodePropertyInfo.showMandatoryError(reader, mandatoryFlag, decoders); } return newInstance.apply(defArgs); } final Object[] args = defArgs.clone(); long currentMandatory = mandatoryFlag; int i = 0; while(i < decoders.length) { final DecodePropertyInfo<JsonReader.ReadObject> ri = decoders[i++]; final int weakHash = reader.fillNameWeakHash(); if (weakHash != ri.weakHash || !reader.wasLastName(ri.nameBytes)) { return readObjectSlow(args, reader, currentMandatory); } reader.getNextToken(); if (ri.nonNull && reader.wasNull()) { throw reader.newParseErrorWith("Null value found for non-null attribute", ri.name); } args[ri.index] = ri.value.read(reader); currentMandatory = currentMandatory & ri.mandatoryValue; if (reader.getNextToken() == ',' && i != decoders.length) reader.getNextToken(); else break; } return finalChecks(args, reader, currentMandatory); }
Example 5
Source File: ArrayDecoder.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 5 votes |
public ArrayDecoder( final T[] emptyInstance, final JsonReader.ReadObject<T> decoder) { if (emptyInstance == null) throw new IllegalArgumentException("emptyInstance can't be null"); if (decoder == null) throw new IllegalArgumentException("decoder can't be null"); this.emptyInstance = emptyInstance; this.decoder = decoder; }
Example 6
Source File: AttributeDecoder.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 5 votes |
AttributeDecoder( final Settings.BiConsumer<T, P> write, final JsonReader.ReadObject<P> decoder) { if (write == null) throw new IllegalArgumentException("write can't be null"); if (decoder == null) throw new IllegalArgumentException("decoder can't be null"); this.write = write; this.decoder = decoder; }
Example 7
Source File: CollectionDecoder.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 5 votes |
public CollectionDecoder( final Type manifest, final Callable<T> newInstance, final JsonReader.ReadObject<E> decoder) { if (manifest == null) throw new IllegalArgumentException("manifest can't be null"); if (newInstance == null) throw new IllegalArgumentException("create can't be null"); if (decoder == null) throw new IllegalArgumentException("decoder can't be null"); this.manifest = manifest; this.newInstance = newInstance; this.decoder = decoder; }
Example 8
Source File: MapDecoder.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 5 votes |
public MapDecoder( final Type manifest, final Callable<T> newInstance, final JsonReader.ReadObject<K> keyDecoder, final JsonReader.ReadObject<V> valueDecoder) { if (manifest == null) throw new IllegalArgumentException("manifest can't be null"); if (newInstance == null) throw new IllegalArgumentException("create can't be null"); if (keyDecoder == null) throw new IllegalArgumentException("keyDecoder can't be null"); if (valueDecoder == null) throw new IllegalArgumentException("valueDecoder can't be null"); this.manifest = manifest; this.newInstance = newInstance; this.keyDecoder = keyDecoder; this.valueDecoder = valueDecoder; }
Example 9
Source File: OptionalDecoder.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 4 votes |
public OptionalDecoder(final JsonReader.ReadObject<T> decoder) { if (decoder == null) throw new IllegalArgumentException("decoder can't be null"); this.decoder = decoder; }