use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project atsd-api-test by axibase.
the class TableMetaDataDeserializer method deserialize.
@Override
public TableMetaData deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
String jsonText = jsonParser.readValueAsTree().toString();
TableMetaData result;
try {
result = SqlTableParser.parseMeta(new JSONObject(jsonText));
} catch (JSONException je) {
throw new JsonParseException(jsonParser, je.getMessage());
}
return result;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project spf4j by zolyfarkas.
the class SampleNode method parseD3Json.
// not that weak here...
@SuppressFBWarnings("WEM_WEAK_EXCEPTION_MESSAGING")
private static void parseD3Json(final JsonParser jsonP, final BiConsumer<Method, SampleNode> consumer) throws IOException {
String methodName = null;
SampleNode sn = new SampleNode(-1);
while (true) {
JsonToken nextToken = jsonP.nextToken();
if (nextToken == JsonToken.FIELD_NAME) {
String fieldName = jsonP.getCurrentName();
switch(fieldName) {
case "name":
consume(jsonP, JsonToken.VALUE_STRING);
methodName = jsonP.getText();
break;
case "value":
consume(jsonP, JsonToken.VALUE_NUMBER_INT);
sn.sampleCount = jsonP.getIntValue();
break;
case "children":
consume(jsonP, JsonToken.START_ARRAY);
while (jsonP.nextToken() != JsonToken.END_ARRAY) {
parseD3Json(jsonP, sn::put);
}
break;
default:
throw new JsonParseException(jsonP, "Unexpected field name : " + fieldName);
}
} else if (nextToken == JsonToken.END_OBJECT) {
if (methodName == null) {
throw new JsonParseException(jsonP, "name field not found");
}
if (sn.sampleCount < 0) {
throw new JsonParseException(jsonP, "value field not found");
}
consumer.accept(Methods.from(methodName), sn);
return;
} else {
throw new JsonParseException(jsonP, "Unexpected " + nextToken);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project spf4j by zolyfarkas.
the class SampleNode method parseInto.
public static void parseInto(final JsonParser jsonP, final SampleNode parentNode) throws IOException {
consume(jsonP, JsonToken.FIELD_NAME);
String name = jsonP.getCurrentName();
consume(jsonP, JsonToken.VALUE_NUMBER_INT);
int sc = jsonP.getIntValue();
JsonToken nextToken = jsonP.nextToken();
Method method = Methods.from(name);
SampleNode sn = parentNode.get(method);
if (sn == null) {
sn = new SampleNode(sc);
parentNode.put(method, sn);
} else {
sn.sampleCount += sc;
}
if (nextToken == JsonToken.END_OBJECT) {
return;
} else if (nextToken == JsonToken.FIELD_NAME) {
consume(jsonP, JsonToken.START_ARRAY);
while (jsonP.nextToken() != JsonToken.END_ARRAY) {
parseInto(jsonP, sn);
}
consume(jsonP, JsonToken.END_OBJECT);
} else {
throw new JsonParseException(jsonP, "Expected field name or end Object, not: " + nextToken);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project curiostack by curioswitch.
the class ParseSupport method parseUInt64.
/**
* Parsers a uint64 value out of the input.
*/
public static long parseUInt64(JsonParser parser) throws IOException {
// cover the vast majority of cases.
try {
long result = parseLong(parser);
if (result >= 0) {
// Only need to check the uint32 range if the parsed long is negative.
return result;
}
} catch (JsonParseException | InputCoercionException | NumberFormatException e) {
// Fall through.
}
final BigInteger value;
try {
BigDecimal decimal = new BigDecimal(parser.getTextCharacters(), parser.getTextOffset(), parser.getTextLength());
value = decimal.toBigIntegerExact();
} catch (ArithmeticException | NumberFormatException e) {
throw new InvalidProtocolBufferException("Not an uint64 value: " + parser.getText());
}
if (value.compareTo(BigInteger.ZERO) < 0 || value.compareTo(MAX_UINT64) > 0) {
throw new InvalidProtocolBufferException("Out of range uint64 value: " + parser.getText());
}
return value.longValue();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project qpid-broker-j by apache.
the class CompressedResponsesTest method doCompressionTest.
private void doCompressionTest(final boolean allowCompression, final boolean acceptCompressed) throws Exception {
final boolean expectCompression = allowCompression && acceptCompressed;
getHelper().submitRequest("plugin/httpManagement", "POST", Collections.singletonMap("compressResponses", expectCompression), SC_OK);
HttpURLConnection conn = getHelper().openManagementConnection("/service/metadata", "GET");
try {
if (acceptCompressed) {
conn.setRequestProperty("Accept-Encoding", "gzip");
}
conn.connect();
String contentEncoding = conn.getHeaderField("Content-Encoding");
if (expectCompression) {
assertEquals("gzip", contentEncoding);
} else {
if (contentEncoding != null) {
assertEquals("identity", contentEncoding);
}
}
byte[] bytes;
try (ByteArrayOutputStream contentBuffer = new ByteArrayOutputStream()) {
ByteStreams.copy(conn.getInputStream(), contentBuffer);
bytes = contentBuffer.toByteArray();
}
try (InputStream jsonStream = expectCompression ? new GZIPInputStream(new ByteArrayInputStream(bytes)) : new ByteArrayInputStream(bytes)) {
ObjectMapper mapper = new ObjectMapper();
try {
mapper.readValue(jsonStream, LinkedHashMap.class);
} catch (JsonParseException | JsonMappingException e) {
fail("Message was not in correct format");
}
}
} finally {
conn.disconnect();
}
}
Aggregations