All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dslplatform.json.runtime.LazyAttributeDecoder Maven / Gradle / Ivy

There is a newer version: 1.10.0
Show newest version
package com.dslplatform.json.runtime;

import com.dslplatform.json.DslJson;
import com.dslplatform.json.JsonReader;
import com.dslplatform.json.SerializationException;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.function.BiConsumer;

class LazyAttributeDecoder implements JsonReader.BindObject {

	private final BiConsumer write;
	private JsonReader.ReadObject

decoder; private final DslJson json; private final Type type; LazyAttributeDecoder( final BiConsumer write, final DslJson json, final Type type) { if (write == null) throw new IllegalArgumentException("write can't be null"); if (json == null) throw new IllegalArgumentException("json can't be null"); if (type == null) throw new IllegalArgumentException("type can't be null"); this.write = write; this.json = json; this.type = type; } @Override public T bind(final JsonReader reader, final T instance) throws IOException { if (decoder == null) { decoder = json.tryFindReader(type); if (decoder == null) { throw new SerializationException("Unable to find reader for " + type); } } final P attr = decoder.read(reader); write.accept(instance, attr); return instance; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy