當前位置: 首頁>>代碼示例>>Java>>正文


Java Configuration類代碼示例

本文整理匯總了Java中com.jayway.jsonpath.Configuration的典型用法代碼示例。如果您正苦於以下問題:Java Configuration類的具體用法?Java Configuration怎麽用?Java Configuration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Configuration類屬於com.jayway.jsonpath包,在下文中一共展示了Configuration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: evaluateJsonPathToString

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
/**
 * Evaluates provided JSONPath expression into the {@link String}
 *
 * @param evalExpression Expression to evaluate
 * @param jsonSource JSON source
 * @return Evaluation result
 */
public static String evaluateJsonPathToString(String evalExpression,
                                              String jsonSource) {
    try {
        List<Object> parsedData =
                JsonPath.
                        using(Configuration.
                                defaultConfiguration().
                                addOptions(
                                        ALWAYS_RETURN_LIST,
                                        SUPPRESS_EXCEPTIONS)).
                        parse(jsonSource).
                        read(evalExpression);

        return collectionIsNotEmpty(parsedData) ?
                String.valueOf(
                        parsedData.
                                get(FIRST_ELEMENT)) :
                EMPTY;
    } catch (Exception e) {
        LOG.warning(COMMON_EVAL_ERROR_MESSAGE);
    }

    return EMPTY;
}
 
開發者ID:shimkiv,項目名稱:trust-java,代碼行數:32,代碼來源:EvaluationUtils.java

示例2: assertPaths

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
private void assertPaths(JsonNode node, boolean shouldExist, String... paths) {
    Object document = Configuration.defaultConfiguration().jsonProvider().parse(node.toString());
    for (String path : paths) {
        try {
            Object object = JsonPath.read(document, path);
            if (isIndefinite(path)) {
                Collection c = (Collection) object;
                assertThat(c.isEmpty()).isNotEqualTo(shouldExist);
            } else if (!shouldExist) {
                Assert.fail("Expected path not to be found: " + path);
            }
        } catch (PathNotFoundException e) {
            if (shouldExist) {
                Assert.fail("Path not found: " + path);
            }
        }
    }
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:19,代碼來源:IntegrationTestCase.java

示例3: before

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
/**
 * Override to set up your specific external resource.
 */
@Override
public void before() {
  saveDefaults();
  Configuration.setDefaults(new Defaults() {

    private final JsonProvider jsonProvider = new JacksonJsonProvider();
    private final MappingProvider mappingProvider = new JacksonMappingProvider();

    @Override
    public JsonProvider jsonProvider() {
      return jsonProvider;
    }

    @Override
    public MappingProvider mappingProvider() {
      return mappingProvider;
    }

    @Override
    public Set<Option> options() {
      return EnumSet.noneOf(Option.class);
    }

  });
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:29,代碼來源:UseJacksonForJsonPathRule.java

示例4: restoreDefaults

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
private void restoreDefaults() {
  if (!this.hadDefaults) {
    return;
  }
  Configuration.setDefaults(new Defaults() {

    @Override
    public JsonProvider jsonProvider() {
      return jsonProvider;
    }

    @Override
    public MappingProvider mappingProvider() {
      return mappingProvider;
    }

    @Override
    public Set<Option> options() {
      return options;
    }

  });
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:24,代碼來源:UseJacksonForJsonPathRule.java

示例5: setDefaults

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
public static void setDefaults() {
    Configuration.setDefaults(new Configuration.Defaults() {
        private final JsonProvider jsonProvider = new JacksonJsonProvider();
        private final MappingProvider mappingProvider = new JacksonMappingProvider();

        @Override
        public JsonProvider jsonProvider() {
            return jsonProvider;
        }

        @Override
        public MappingProvider mappingProvider() {
            return mappingProvider;
        }

        @Override
        public Set<Option> options() {
            return EnumSet.noneOf(Option.class);
        }
    });
}
 
開發者ID:revinate,項目名稱:assertj-json,代碼行數:22,代碼來源:TestConfig.java

示例6: map

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
@Override
public <T> T map(final Object source, final Class<T> targetType, final Configuration configuration) {
  if (source == null) {
    return null;
  }
  if (targetType.isAssignableFrom(source.getClass())) {
    return (T) source;
  }
  try {
    if (targetType.isAssignableFrom(ArrayList.class) && configuration.jsonProvider().isArray(source)) {
      int length = configuration.jsonProvider().length(source);
      @SuppressWarnings("rawtypes")
      ArrayList list = new ArrayList(length);
      for (Object o : configuration.jsonProvider().toIterable(source)) {
        list.add(o);
      }
      return (T) list;
    }
  } catch (Exception e) {

  }
  throw new MappingException("Cannot convert a " + source.getClass().getName() + " to a " + targetType
      + " use Tapestry's TypeCoercer instead.");
}
 
開發者ID:osswangxining,項目名稱:another-rule-based-analytics-on-spark,代碼行數:25,代碼來源:TapestryMappingProvider.java

示例7: map

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
@Override
public <T> T map(Object source, Class<T> targetType, Configuration configuration) {
    if(source == null){
        return null;
    }
    if (targetType.isAssignableFrom(source.getClass())) {
        return (T) source;
    }
    try {
        if(!configuration.jsonProvider().isMap(source) && !configuration.jsonProvider().isArray(source)){
            return factory.call().getMapper(targetType).convert(source);
        }
        String s = configuration.jsonProvider().toJson(source);
        return (T) JSONValue.parse(s, targetType);
    } catch (Exception e) {
        throw new MappingException(e);
    }

}
 
開發者ID:osswangxining,項目名稱:another-rule-based-analytics-on-spark,代碼行數:20,代碼來源:JsonSmartMappingProvider.java

示例8: personToJsonString

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
@Test
public void personToJsonString() {
    Person duke = new Person("Duke", LocalDate.of(1995, 5, 23));
    duke.setPhoneNumbers(
            Arrays.asList(
                    new PhoneNumber(HOME, "100000"),
                    new PhoneNumber(OFFICE, "200000")
            )
    );

    Jsonb jsonMapper = JsonbBuilder.create();
    String json = jsonMapper.toJson(duke);

    LOG.log(Level.INFO, "converted json result: {0}", json);

    String name = JsonPath.parse(json).read("$.name");
    assertEquals("Duke", name);

    Configuration config = Configuration.defaultConfiguration()
            .jsonProvider(new GsonJsonProvider())
            .mappingProvider(new GsonMappingProvider());
    TypeRef<List<String>> typeRef = new TypeRef<List<String>>() {
    };

    List<String> numbers = JsonPath.using(config).parse(json).read("$.phoneNumbers[*].number", typeRef);

    assertEquals(Arrays.asList("100000", "200000"), numbers);
}
 
開發者ID:hantsy,項目名稱:ee8-sandbox,代碼行數:29,代碼來源:JsonbTest.java

示例9: SelectJsonPath

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
@Inject
public SelectJsonPath(ObjectMapper objectMapper) {
    configuration = Configuration.builder()
            .options(Option.SUPPRESS_EXCEPTIONS)
            .jsonProvider(new JacksonJsonNodeJsonProvider(objectMapper))
            .build();

    jsonParam = ParameterDescriptor.type("json", JsonNode.class).description("A parsed JSON tree").build();
    // sigh generics and type erasure
    //noinspection unchecked
    pathsParam = ParameterDescriptor.type("paths",
                                          (Class<Map<String, String>>) new TypeLiteral<Map<String, String>>() {}.getRawType(),
                                          (Class<Map<String, JsonPath>>) new TypeLiteral<Map<String, JsonPath>>() {}.getRawType())
            .transform(inputMap -> inputMap
                    .entrySet().stream()
                    .collect(toMap(Map.Entry::getKey, e -> JsonPath.compile(e.getValue()))))
            .description("A map of names to a JsonPath expression, see http://jsonpath.com")
            .build();
}
 
開發者ID:Graylog2,項目名稱:graylog-plugin-pipeline-processor,代碼行數:20,代碼來源:SelectJsonPath.java

示例10: afterPropertiesSet

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
@Override
public void afterPropertiesSet() throws Exception {
    
    Configuration.setDefaults(new Configuration.Defaults() {

        private final JsonProvider jsonProvider = new JacksonJsonProvider();
        
        @Override
        public JsonProvider jsonProvider() {
            return jsonProvider;
        }

        @Override
        public Set<Option> options() {
            return EnumSet.noneOf(Option.class);
        }

        @Override
        public MappingProvider mappingProvider() {
            return new JacksonMappingProvider();
        }
    });
    
}
 
開發者ID:major2015,項目名稱:easyrec_major,代碼行數:25,代碼來源:JSONProfileServiceImpl.java

示例11: testParseString

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
@Test
public void testParseString () throws IOException
{
    BasicConfigurator.configure ();
    String f = "../tests/data/complex1.json";
    File file = new File (f.replace ('/', File.separatorChar));
    String str = Utils.getString (file);

    JsonPathProvider provider = new JsonPathProvider ();

    Configuration pathConfig = Configuration.defaultConfiguration ().jsonProvider (provider);
    JsonPath path = JsonPath.compile ("$.strange");
    JsonValue value = path.read (str, pathConfig);

    // we cannot directly compare the output since the attribute ordering
    // can vary.
    Assert.assertEquals ("{\"id\":5555,\"price\":[1,2,3],\"customer\":\"john...\"}".length (), provider.toJson (value).length ());
}
 
開發者ID:coconut2015,項目名稱:cookjson,代碼行數:19,代碼來源:JsonPathProviderTest.java

示例12: testBson

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
@Test
public void testBson () throws IOException
{
    BasicConfigurator.configure ();
    String f = "../tests/data/data1.bson";
    File file = new File (f.replace ('/', File.separatorChar));

    JsonPathProvider provider = new JsonPathProvider ();

    Configuration pathConfig = Configuration.defaultConfiguration ().jsonProvider (provider);
    JsonPath path = JsonPath.compile ("$..A");

    JsonProvider p = new CookJsonProvider ();
    HashMap<String, Object> readConfig = new HashMap<String, Object> ();
    readConfig.put (CookJsonProvider.FORMAT, CookJsonProvider.FORMAT_BSON);
    readConfig.put (CookJsonProvider.ROOT_AS_ARRAY, Boolean.TRUE);
    JsonReaderFactory rf = p.createReaderFactory (readConfig);
    JsonReader reader = rf.createReader (new FileInputStream (file));
    JsonStructure obj = reader.read ();
    reader.close ();

    JsonValue value = path.read (obj, pathConfig);

    Assert.assertEquals ("[1,3,5,7]", provider.toJson (value));
}
 
開發者ID:coconut2015,項目名稱:cookjson,代碼行數:26,代碼來源:JsonPathProviderTest.java

示例13: hello

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
@Test
public void hello() throws URISyntaxException, IOException {
    JsonProvider jsonProvider = Configuration.defaultConfiguration().jsonProvider();
    String recordId = "2022320/3F61C612ED9C42CCB85E533B4736795E8BDC7E77";
    String jsonString = readContent("general/td-idf-response.json");
    assertEquals("{", jsonString.substring(0,1));

    TfIdfExtractor extractor = new TfIdfExtractor(new EdmOaiPmhXmlSchema());
    FieldCounter<Double> results = extractor.extract(jsonString, recordId);
    assertEquals(6, results.size());
    assertEquals(new Double(0.0017653998874690505), results.get("dc:title:avg"));
    assertEquals(new Double(0.008826999437345252), results.get("dc:title:sum"));
    assertEquals(new Double(0), results.get("dcterms:alternative:avg"));
    assertEquals(new Double(0), results.get("dcterms:alternative:sum"));
    assertEquals(new Double(0), results.get("dc:description:avg"));
    assertEquals(new Double(0), results.get("dc:description:sum"));
}
 
開發者ID:pkiraly,項目名稱:metadata-qa-api,代碼行數:18,代碼來源:TfIdfExtractorTest.java

示例14: hello

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
@Test
public void hello() throws URISyntaxException, IOException {
    String jsonString = FileUtils.readFirstLine("general/test.json");

    Object jsonDocument = Configuration.defaultConfiguration().jsonProvider().parse(jsonString);
    for (JsonBranch collectionBranch : schema.getCollectionPaths()) {
        Object rawCollection = null;
        try {
            rawCollection = JsonPath.read(jsonDocument, collectionBranch.getJsonPath());
        } catch (PathNotFoundException e) {}
        if (rawCollection != null) {
            if (rawCollection instanceof JSONArray) {
                JSONArray collection = (JSONArray)rawCollection;
                collection.forEach(
                    node -> {
                        processNode(node, collectionBranch.getChildren());
                    }
                );
            } else {
                processNode(rawCollection, collectionBranch.getChildren());
            }
        }
    }
}
 
開發者ID:pkiraly,項目名稱:metadata-qa-api,代碼行數:25,代碼來源:NodeEnabledCalculatorTest.java

示例15: processCustomEvent

import com.jayway.jsonpath.Configuration; //導入依賴的package包/類
private Event processCustomEvent(ReadContext readContext) {
    Configuration conf = Configuration.defaultConfiguration();
    Event event = new Event(attributesSize);
    Object[] data = event.getData();
    Object childObject = readContext.read(DEFAULT_ENCLOSING_ELEMENT);
    readContext = JsonPath.using(conf).parse(childObject);
    for (MappingPositionData mappingPositionData : this.mappingPositions) {
        int position = mappingPositionData.getPosition();
        Object mappedValue;
        try {
            mappedValue = readContext.read(mappingPositionData.getMapping());
            if (mappedValue == null) {
                data[position] = null;
            } else {
                data[position] = attributeConverter.getPropertyValue(mappedValue.toString(),
                        streamAttributes.get(position).getType());
            }
        } catch (PathNotFoundException e) {
            if (failOnMissingAttribute) {
                log.error("Json message " + childObject.toString() +
                        " contains missing attributes. Hence dropping the message.");
                return null;
            }
            data[position] = null;
        }
    }
    return event;
}
 
開發者ID:wso2-extensions,項目名稱:siddhi-map-json,代碼行數:29,代碼來源:JsonSourceMapper.java


注:本文中的com.jayway.jsonpath.Configuration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。