io.github.stewseo.client.json.ObjectBuilderDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yelp-fusion-client Show documentation
Show all versions of yelp-fusion-client Show documentation
java client to build api objects, handle http transport, and parse/deserialize/serialize json to/from json
package io.github.stewseo.client.json;
import io.github.stewseo.client.util.ObjectBuilder;
import jakarta.json.stream.JsonParser;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
public class ObjectBuilderDeserializer> extends DelegatingDeserializer {
private final JsonpDeserializer builderDeserializer;
public static , T> JsonpDeserializer lazy(
Supplier builderCtor,
Consumer> builderDeserializerSetup
) {
return new LazyDeserializer<>(() -> {
ObjectDeserializer builderDeser = new ObjectDeserializer<>(builderCtor);
builderDeserializerSetup.accept(builderDeser);
return new ObjectBuilderDeserializer<>(builderDeser);
});
}
public static JsonpDeserializer lazy(
Supplier builderCtor,
Consumer> builderDeserializerSetup,
Function buildFn
) {
return new LazyDeserializer<>(() -> {
ObjectDeserializer builderDeser = new ObjectDeserializer<>(builderCtor);
builderDeserializerSetup.accept(builderDeser);
return new BuildFunctionDeserializer<>(builderDeser, buildFn);
});
}
public static > JsonpDeserializer createForObject(
Supplier ctor,
Consumer> configurer
) {
ObjectDeserializer op = new ObjectDeserializer<>(ctor);
configurer.accept(op);
return new ObjectBuilderDeserializer<>(op);
}
public ObjectBuilderDeserializer(JsonpDeserializer builderDeserializer) {
this.builderDeserializer = builderDeserializer;
}
@Override
protected JsonpDeserializer unwrap() {
return builderDeserializer;
}
@Override
public T deserialize(JsonParser parser, JsonpMapper mapper) {
ObjectBuilder builder = builderDeserializer.deserialize(parser, mapper);
return builder == null ? null : builder.build();
}
@Override
public T deserialize(JsonParser parser, JsonpMapper mapper, JsonParser.Event event) {
ObjectBuilder builder = builderDeserializer.deserialize(parser, mapper, event);
return builder == null ? null : builder.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy