use of jakarta.json.JsonObject in project elasticsearch-java by elastic.
the class JsonpUtils method lookAheadFieldValue.
/**
* Looks ahead a field value in the Json object from the upcoming object in a parser, which should be on the
* START_OBJECT event.
*
* Returns a pair containing that value and a parser that should be used to actually parse the object
* (the object has been consumed from the original one).
*/
public static Map.Entry<String, JsonParser> lookAheadFieldValue(String name, String defaultValue, JsonParser parser, JsonpMapper mapper) {
// FIXME: need a buffering parser wrapper so that we don't roundtrip through a JsonObject and a String
// FIXME: resulting parser should return locations that are offset with the original parser's location
JsonObject object = parser.getObject();
String result = object.getString(name, null);
if (result == null) {
result = defaultValue;
}
if (result == null) {
throw new JsonParsingException("Property '" + name + "' not found", parser.getLocation());
}
return new AbstractMap.SimpleImmutableEntry<>(result, objectParser(object, mapper));
}
use of jakarta.json.JsonObject in project avro-util by linkedin.
the class TestJsonParsing method testSimpleSchema.
@Test
public void testSimpleSchema() throws Exception {
String avsc = TestUtil.load("schemas/TestRecord.avsc");
JsonReader referenceReader = Json.createReader(new StringReader(avsc));
JsonObject referenceObject = referenceReader.readObject();
JsonReaderExt ourReader = new JsonReaderWithLocations(new StringReader(avsc), null);
JsonObjectExt ourObject = ourReader.readObject();
// assert we read everything correctly. our equals() implementations are not
// commutative with regular json-p objects (yet?)
// noinspection SimplifiableAssertion
Assert.assertTrue(referenceObject.equals(ourObject));
// see that we have text locations for json values
JsonValueExt fields = ourObject.get("fields");
JsonLocation startLocation = fields.getStartLocation();
JsonLocation endLocation = fields.getEndLocation();
Assert.assertEquals(startLocation.getLineNumber(), 6);
Assert.assertEquals(endLocation.getLineNumber(), 70);
}
use of jakarta.json.JsonObject in project opensearch-java by opensearch-project.
the class UnionDeserializer method deserialize.
@Override
public Union deserialize(JsonParser parser, JsonpMapper mapper, Event event) {
EventHandler<Union, Kind, Member> member = otherMembers.get(event);
if (member == null && event == Event.START_OBJECT && !objectMembers.isEmpty()) {
// Parse as an object to find matching field names
JsonObject object = parser.getObject();
for (String field : object.keySet()) {
member = objectMembers.get(field);
if (member != null) {
break;
}
}
if (member == null) {
member = fallbackObjectMember;
}
if (member != null) {
// Traverse the object we have inspected
parser = JsonpUtils.objectParser(object, mapper);
event = parser.next();
}
}
if (member == null) {
throw new JsonParsingException("Cannot determine what union member to deserialize", parser.getLocation());
}
return member.deserialize(parser, mapper, event, buildFn);
}
use of jakarta.json.JsonObject in project opensearch-java by opensearch-project.
the class JsonpUtils method lookAheadFieldValue.
/**
* Looks ahead a field value in the Json object from the upcoming object in a parser, which should be on the
* START_OBJECT event.
*
* Returns a pair containing that value and a parser that should be used to actually parse the object
* (the object has been consumed from the original one).
*/
public static Map.Entry<String, JsonParser> lookAheadFieldValue(String name, String defaultValue, JsonParser parser, JsonpMapper mapper) {
// FIXME: need a buffering parser wrapper so that we don't roundtrip through a JsonObject and a String
// FIXME: resulting parser should return locations that are offset with the original parser's location
JsonObject object = parser.getObject();
String result = object.getString(name, null);
if (result == null) {
result = defaultValue;
}
if (result == null) {
throw new JsonParsingException("Property '" + name + "' not found", parser.getLocation());
}
return new AbstractMap.SimpleImmutableEntry<>(result, objectParser(object, mapper));
}
use of jakarta.json.JsonObject in project helidon by oracle.
the class MainTest method personalizedGet.
private static JsonObject personalizedGet(String name) {
JsonObject result = get("/greet/" + name);
expectedPersonalizedGets++;
return result;
}
Aggregations