Search in sources :

Example 11 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project openhab1-addons by openhab.

the class JsonWeatherParser method parseInto.

/**
     * {@inheritDoc}
     */
@Override
public void parseInto(InputStream is, Weather weather) throws Exception {
    JsonFactory jsonFactory = new JsonFactory();
    JsonParser jp = jsonFactory.createParser(is);
    jp.nextValue();
    handleToken(jp, null, weather);
    jp.close();
    super.parseInto(is, weather);
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 12 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project midpoint by Evolveum.

the class AbstractJsonLexicalProcessor method parseFromStart.

@NotNull
private RootXNode parseFromStart(JsonParser unconfiguredParser, ParsingContext parsingContext) throws SchemaException {
    JsonParsingContext ctx = null;
    try {
        JsonParser parser = configureParser(unconfiguredParser);
        parser.nextToken();
        if (parser.currentToken() == null) {
            throw new SchemaException("Nothing to parse: the input is empty.");
        }
        ctx = new JsonParsingContext(parser, parsingContext);
        XNode xnode = parseValue(ctx);
        if (!(xnode instanceof MapXNode) || ((MapXNode) xnode).size() != 1) {
            throw new SchemaException("Expected MapXNode with a single key; got " + xnode + " instead. At " + getPositionSuffix(ctx));
        }
        processDefaultNamespaces(xnode, null, ctx);
        processSchemaNodes(xnode);
        Entry<QName, XNode> entry = ((MapXNode) xnode).entrySet().iterator().next();
        RootXNode root = new RootXNode(entry.getKey(), entry.getValue());
        if (entry.getValue() != null) {
            // TODO - ok ????
            root.setTypeQName(entry.getValue().getTypeQName());
        }
        return root;
    } catch (IOException e) {
        throw new SchemaException("Cannot parse JSON/YAML object: " + e.getMessage() + (ctx != null ? " At: " + getPositionSuffix(ctx) : ""), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) JsonParser(com.fasterxml.jackson.core.JsonParser) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project OpenAM by OpenRock.

the class RestSTSInstanceConfigTest method testJsonStringMarshalling.

@Test
public void testJsonStringMarshalling() throws IOException {
    RestSTSInstanceConfig origConfig = createInstanceConfig("/bob", WITH_TLS_OFFLOAD_CONFIG, WITH_SAML2_CONFIG, WITH_OIDC_CONFIG, WITH_CUSTOM_VALIDATOR, WITH_CUSTOM_PROVIDER, WITH_CTS_TOKEN_PERSISTENCE);
    /*
        This is how the Crest HttpServletAdapter ultimately constitutes a JsonValue from a json string. See the
        org.forgerock.json.resource.servlet.HttpUtils.parseJsonBody (called from HttpServletAdapter.getJsonContent)
        for details.
         */
    JsonParser parser = new ObjectMapper().getFactory().createParser(origConfig.toJson().toString());
    final Object content = parser.readValueAs(Object.class);
    assertEquals(origConfig, RestSTSInstanceConfig.fromJson(new JsonValue(content)));
}
Also used : JsonValue(org.forgerock.json.JsonValue) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.testng.annotations.Test)

Example 14 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project OpenAM by OpenRock.

the class SoapSTSInstanceConfigTest method testJsonStringMarshalling.

@Test
public void testJsonStringMarshalling() throws IOException {
    SoapSTSInstanceConfig origConfig = createInstanceConfig("/bobo/instance1", "http://host.com:8080/am", WITH_KEYSTORE_CONFIG, WITH_VALIDATE_CONFIG, DELEGATION_VALIDATORS_SPECIFIED, CUSTOM_DELEGATION_HANDLER, WITH_SAML2_CONFIG, WITH_OIDC_CONFIG, !WITH_CTS_TOKEN_PERSISTENCE);
    /*
        This is how the Crest HttpServletAdapter ultimately constitutes a JsonValue from a json string. See the
        org.forgerock.json.resource.servlet.HttpUtils.parseJsonBody (called from HttpServletAdapter.getJsonContent)
        for details.
         */
    JsonParser parser = new ObjectMapper().getFactory().createParser(origConfig.toJson().toString());
    final Object content = parser.readValueAs(Object.class);
    assertEquals(origConfig, SoapSTSInstanceConfig.fromJson(new JsonValue(content)));
}
Also used : JsonValue(org.forgerock.json.JsonValue) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.testng.annotations.Test)

Example 15 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project jackson-core by FasterXML.

the class ValueConversionsTest method _testAsInt.

private void _testAsInt(int mode) throws Exception {
    final String input = "[ 1, -3, 4.98, true, false, null, \"-17\", \"foo\" ]";
    JsonParser p = createParser(mode, input);
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    assertEquals(0, p.getValueAsLong());
    assertEquals(9, p.getValueAsLong(9));
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(1, p.getValueAsLong());
    assertEquals(1, p.getValueAsLong(-99));
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(-3, p.getValueAsLong());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
    assertEquals(4, p.getValueAsLong());
    assertEquals(4, p.getValueAsLong(99));
    assertToken(JsonToken.VALUE_TRUE, p.nextToken());
    assertEquals(1, p.getValueAsLong());
    assertToken(JsonToken.VALUE_FALSE, p.nextToken());
    assertEquals(0, p.getValueAsLong());
    assertToken(JsonToken.VALUE_NULL, p.nextToken());
    assertEquals(0, p.getValueAsLong());
    assertEquals(0, p.getValueAsLong(27));
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals(-17, p.getValueAsLong());
    assertEquals(-17, p.getValueAsLong(3));
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals(0, p.getValueAsLong());
    assertEquals(9, p.getValueAsLong(9));
    assertToken(JsonToken.END_ARRAY, p.nextToken());
    assertEquals(0, p.getValueAsLong());
    assertEquals(9, p.getValueAsLong(9));
    p.close();
}
Also used : JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)587 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)258 JacksonWrapperParser (com.abubusoft.kripton.persistence.JacksonWrapperParser)258 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 ArrayList (java.util.ArrayList)171 IOException (java.io.IOException)126 JsonFactory (com.fasterxml.jackson.core.JsonFactory)76 Test (org.junit.Test)57 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)51 JsonNode (com.fasterxml.jackson.databind.JsonNode)46 HashSet (java.util.HashSet)43 JsonToken (com.fasterxml.jackson.core.JsonToken)41 LinkedHashSet (java.util.LinkedHashSet)38 HashMap (java.util.HashMap)35 LinkedList (java.util.LinkedList)26 JsonParseException (com.fasterxml.jackson.core.JsonParseException)23 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)21 List (java.util.List)21 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)20 InputStream (java.io.InputStream)20