Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.clients.json;
import co.elastic.clients.util.QuadConsumer;
import jakarta.json.stream.JsonParser;
import jakarta.json.stream.JsonParser.Event;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.ObjIntConsumer;
import java.util.function.Supplier;
public class ObjectDeserializer implements JsonpDeserializer {
/** A field deserializer parses a value and calls the setter on the target object. */
public abstract static class FieldDeserializer {
protected final String name;
public FieldDeserializer(String name) {
this.name = name;
}
public abstract void deserialize(JsonParser parser, JsonpMapper mapper, String fieldName, ObjectType object);
public abstract void deserialize(JsonParser parser, JsonpMapper mapper, String fieldName, ObjectType object, Event event);
}
/** Field deserializer for objects (and boxed primitives) */
public static class FieldObjectDeserializer extends FieldDeserializer {
private final BiConsumer setter;
private final JsonpDeserializer deserializer;
public FieldObjectDeserializer(
BiConsumer setter, JsonpDeserializer deserializer,
String name
) {
super(name);
this.setter = setter;
this.deserializer = deserializer;
}
public String name() {
return this.name;
}
public void deserialize(JsonParser parser, JsonpMapper mapper, String fieldName, ObjectType object) {
FieldType fieldValue = deserializer.deserialize(parser, mapper);
setter.accept(object, fieldValue);
}
public void deserialize(JsonParser parser, JsonpMapper mapper, String fieldName, ObjectType object, Event event) {
JsonpUtils.ensureAccepts(deserializer, parser, event);
FieldType fieldValue = deserializer.deserialize(parser, mapper, event);
setter.accept(object, fieldValue);
}
}
private static final FieldDeserializer> IGNORED_FIELD = new FieldDeserializer