当前位置: 首页>>代码示例>>Java>>正文


Java JsonUtils类代码示例

本文整理汇总了Java中com.bazaarvoice.jolt.JsonUtils的典型用法代码示例。如果您正苦于以下问题:Java JsonUtils类的具体用法?Java JsonUtils怎么用?Java JsonUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JsonUtils类属于com.bazaarvoice.jolt包,在下文中一共展示了JsonUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: map

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
public Collection<DynamicProperty> map(String source) {
    //Default value is equal to the input json value (in case empty jolt specs)
    String jsonProperties = source;

    ArrayList transformed = (ArrayList) chainr.transform(JsonUtils.jsonToMap(source));
    jsonProperties = JsonUtils.toJsonString(transformed);

    //Now ensure current json properties is well formatted.
//    if (validateJson(jsonProperties)) {

    List<Object> items = JsonUtils.jsonToList(jsonProperties);
    Object collect = items.stream()
            .map(item -> {
                Map<String, String> mapItem = (Map<String, String>) item;
                Object key = mapItem.get("key");
                if (key instanceof Number) {
                    return new DynamicProperty(key.toString(), mapItem.get("value"));
                } else {
                    return new DynamicProperty((String) key, mapItem.get("value"));
                }
            })
            .collect(Collectors.toList());

    return (Collection<DynamicProperty>) collect;
}
 
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:26,代码来源:JoltMapper.java

示例2: getCases

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
@DataProvider
public Iterator<Object[]> getCases() throws IOException {

    String testPath = "/json/chainr/guice_spec_with_context.json";
    Map<String, Object> testSuite = JsonUtils.classpathToMap( testPath );

    Object spec = testSuite.get( "spec" );
    List<Map> tests = (List<Map>) testSuite.get( "tests" );

    List<Object[]> accum = Lists.newLinkedList();

    for ( Map testCase : tests ) {

        String testCaseName = (String) testCase.get( "testCaseName" );
        Object input = testCase.get( "input" );
        Map<String,Object> context = (Map<String,Object>) testCase.get( "context" );
        Object expected = testCase.get( "expected" );

        accum.add( new Object[] { testCaseName, spec, input, context, expected } );
    }

    return accum.iterator();
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:24,代码来源:GuicedChainrContextTest.java

示例3: itBlowsUpForMissingProviderStockTransform

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
@Test( expectedExceptions = SpecException.class )
public void itBlowsUpForMissingProviderStockTransform() throws IOException
{
    String testPath = "/json/chainr/guice_spec.json";
    Map<String, Object> testUnit = JsonUtils.classpathToMap( testPath );

    Object spec = testUnit.get( "spec" );

    Module parentModule = new AbstractModule() {
        @Override
        protected void configure() {
        }

        @Provides
        public GuiceSpecDrivenTransform.GuiceConfig getConfigD() {
            return new GuiceSpecDrivenTransform.GuiceConfig( "dd" );
        }
    };

    Chainr.fromSpec( spec, new GuiceChainrInstantiator( parentModule ) );
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:22,代码来源:GuicedChainrTest.java

示例4: itBlowsUpForMissingProviderSpecTransform

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
@Test( expectedExceptions = SpecException.class )
public void itBlowsUpForMissingProviderSpecTransform() throws IOException
{
    String testPath = "/json/chainr/guice_spec.json";
    Map<String, Object> testUnit = JsonUtils.classpathToMap( testPath );

    Object spec = testUnit.get( "spec" );

    Module parentModule = new AbstractModule() {
        @Override
        protected void configure() {
        }

        @Provides
        public GuiceTransform.GuiceConfig getConfigC() {
            return new GuiceTransform.GuiceConfig( "c", "cc" );
        }
    };

    Chainr.fromSpec( spec, new GuiceChainrInstantiator( parentModule ) );
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:22,代码来源:GuicedChainrTest.java

示例5: testAutoArray

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
@Test
public void testAutoArray() throws IOException
{
    SimpleTraversal<String> traversal = SimpleTraversal.newTraversal( "a.[].b" );

    Object expected = JsonUtils.jsonToMap( "{ \"a\" : [ { \"b\" : \"one\" }, { \"b\" : \"two\" } ] }" );

    Object actual = new HashMap();

    Assert.assertFalse( traversal.get( actual ).isPresent() );
    Assert.assertEquals( 0, ((HashMap) actual).size() ); // get didn't add anything

    // Add two things and validate the Auto Expand array
    Assert.assertEquals( "one", traversal.set( actual, "one" ).get() );
    Assert.assertEquals( "two", traversal.set( actual, "two" ).get() );

    JoltTestUtil.runDiffy( expected, actual );
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:19,代码来源:SimpleTraversalTest.java

示例6: testOverwrite

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
@Test
public void testOverwrite() throws IOException
{
    SimpleTraversal<String> traversal = SimpleTraversal.newTraversal( "a.b" );

    Object actual = JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : \"tuna\" } }" );
    Object expectedOne = JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : \"one\" } }" );
    Object expectedTwo = JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : \"two\" } }" );

    Assert.assertEquals( "tuna", traversal.get( actual ).get() );

    // Set twice and verify that the sets did in fact overwrite
    Assert.assertEquals( "one", traversal.set( actual, "one" ).get() );
    JoltTestUtil.runDiffy( expectedOne, actual );

    Assert.assertEquals( "two", traversal.set( actual, "two" ).get() );
    JoltTestUtil.runDiffy( expectedTwo, actual );
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:19,代码来源:SimpleTraversalTest.java

示例7: shiftrKeyOrderingTestCases

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
@DataProvider
public Object[][] shiftrKeyOrderingTestCases() throws IOException {
    return new Object[][] {
        {
            "Simple * and &",
            JsonUtils.jsonToMap( "{ \"*\" : { \"a\" : \"b\" }, \"&\" : { \"a\" : \"b\" } }" ),
            Arrays.asList( "&(0,0)", "*" )
        },
        {
            "2* and 2&",
            JsonUtils.jsonToMap( "{ \"rating-*\" : { \"a\" : \"b\" }, \"rating-range-*\" : { \"a\" : \"b\" }, \"&\" : { \"a\" : \"b\" }, \"tuna-&(0)\" : { \"a\" : \"b\" } }" ),
            Arrays.asList( "tuna-&(0,0)", "&(0,0)", "rating-range-*", "rating-*" )
        },
        {
            "2& alpha-number based fallback",
            JsonUtils.jsonToMap( "{ \"&\" : { \"a\" : \"b\" }, \"&(0,1)\" : { \"a\" : \"b\" } }" ),
            Arrays.asList( "&(0,0)", "&(0,1)" )
        },
        {
            "2* and 2& alpha fallback",
            JsonUtils.jsonToMap( "{ \"aaaa-*\" : { \"a\" : \"b\" }, \"bbbb-*\" : { \"a\" : \"b\" }, \"aaaa-&\" : { \"a\" : \"b\" }, \"bbbb-&(0)\" : { \"a\" : \"b\" } }" ),
            Arrays.asList( "aaaa-&(0,0)", "bbbb-&(0,0)", "aaaa-*", "bbbb-*" )
        }
    };
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:26,代码来源:KeyOrderingTest.java

示例8: runFixtureTests

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
@Test
public void runFixtureTests() throws IOException {

    String testFixture = "/json/utils/joltUtils-removeRecursive.json";
    @SuppressWarnings("unchecked")
    List<Map<String, Object>> tests = (List<Map<String, Object>>) JsonUtils.classpathToObject( testFixture );

    for ( Map<String,Object> testUnit : tests ) {

        Object data = testUnit.get( "input" );
        String toRemove = (String) testUnit.get( "remove" );
        Object expected = testUnit.get( "expected" );

        JoltUtils.removeRecursive( data, toRemove );

        Diffy.Result result = diffy.diff( expected, data );
        if (!result.isEmpty()) {
            Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString(result.expected) + "\n  actual: " + JsonUtils.toJsonString(result.actual));
        }
    }
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:22,代码来源:JoltUtilsTest.java

示例9: storeTestCases

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
@DataProvider
public Iterator<Object[]> storeTestCases() {

    String testFixture = "/json/utils/joltUtils-store-remove-compact.json";
    @SuppressWarnings("unchecked")
    List<Map<String, Object>> tests = (List<Map<String, Object>>) JsonUtils.classpathToObject( testFixture );

    List<Object[]> testCases = new LinkedList<>();

    for(Map<String, Object> testCase: tests) {
        testCases.add(new Object[] {
                testCase.get("description"),
                testCase.get("source"),
                ((List)testCase.get("path")).toArray(),
                testCase.get("value"),
                testCase.get("output")
        });
    }

    return testCases.iterator();
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:22,代码来源:JoltUtilsTest.java

示例10: deepCopyTest

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
@Test
public void deepCopyTest() throws Exception {

    Object input = JsonUtils.classpathToObject( "/json/deepcopy/original.json" );

    Map<String, Object> fiddle = (Map<String, Object>) DeepCopy.simpleDeepCopy( input );

    JoltTestUtil.runDiffy( "Verify that the DeepCopy did in fact make a copy.", input, fiddle );

    // The test is to make a deep copy, then manipulate the copy, and verify that the original did not change  ;)
    // copy and fiddle
    List array = (List) fiddle.get( "array" );
    array.add( "c" );
    array.set( 1, 3 );
    Map<String,Object> subMap = (Map<String,Object>) fiddle.get( "map" );
    subMap.put("c", "c");
    subMap.put("b", 3 );

    // Verify that the input to the copy was unmodified
    Object unmodified = JsonUtils.classpathToObject( "/json/deepcopy/original.json" );
    JoltTestUtil.runDiffy( "Verify that the deepcopy was actually deep / input is unmodified", unmodified, input );

    // Verify we made the modifications we wanted to.
    Object expectedModified = JsonUtils.classpathToObject( "/json/deepcopy/modifed.json" );
    JoltTestUtil.runDiffy( "Verify fiddled post deepcopy object looks correct / was modifed.", expectedModified, fiddle );
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:27,代码来源:DeepCopyTest.java

示例11: convertJmhJsonData

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
/**
 * Load the JSON template data and convert it.
 */
private static void convertJmhJsonData(InputStream specIn, InputStream jmhIn, OutputStream out) throws IOException {
  List<?> chainrConfig = JsonUtils.jsonToList(specIn);
  Chainr chainr = Chainr.fromSpec(chainrConfig);
  List<Object> input = JsonUtils.jsonToList(jmhIn);
  Object jsonOutput = chainr.transform(input);
  out.write(JsonUtils.toJsonString(jsonOutput).getBytes(StandardCharsets.UTF_8));
}
 
开发者ID:google,项目名称:conscrypt,代码行数:11,代码来源:Main.java

示例12: getTransform

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
private synchronized Transform getTransform() throws Exception {
    if (transform == null) {
        if (log.isDebugEnabled()) {
            String path = getResourceUri();
            log.debug("Jolt content read from resource {} with resourceUri: {} for endpoint {}", new Object[]{getResourceUri(), path, getEndpointUri()});
        }

        // Sortr does not require a spec
        if (this.transformDsl == JoltTransformType.Sortr) {
            this.transform = new Sortr();
        } else {
            // getResourceAsInputStream also considers the content cache
            Object spec = JsonUtils.jsonToObject(getResourceAsInputStream());
            switch(this.transformDsl) {
            case Shiftr:
                this.transform = new Shiftr(spec);
                break;
            case Defaultr:
                this.transform = new Defaultr(spec);
                break;
            case Removr:
                this.transform = new Removr(spec);
                break;
            case Chainr:
            default:
                this.transform = Chainr.fromSpec(spec);
                break;
            }
        }
        
    }
    return transform;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:34,代码来源:JoltEndpoint.java

示例13: onExchange

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
@Override
protected void onExchange(Exchange exchange) throws Exception {
    String path = getResourceUri();
    ObjectHelper.notNull(path, "resourceUri");

    String newResourceUri = exchange.getIn().getHeader(JoltConstants.JOLT_RESOURCE_URI, String.class);
    if (newResourceUri != null) {
        exchange.getIn().removeHeader(JoltConstants.JOLT_RESOURCE_URI);

        log.debug("{} set to {} creating new endpoint to handle exchange", JoltConstants.JOLT_RESOURCE_URI, newResourceUri);
        JoltEndpoint newEndpoint = findOrCreateEndpoint(getEndpointUri(), newResourceUri);
        newEndpoint.onExchange(exchange);
        return;
    }
    Object input;
    if (getInputType() == JoltInputOutputType.JsonString) {
        input = JsonUtils.jsonToObject(exchange.getIn().getBody(InputStream.class));
    } else {
        input = exchange.getIn().getBody();
    }
    Object output = getTransform().transform(input);
            
    // now lets output the results to the exchange
    Message out = exchange.getOut();
    if (getOutputType() == JoltInputOutputType.JsonString) {
        out.setBody(JsonUtils.toJsonString(output));
    } else {
        out.setBody(output);
    }
    out.setHeaders(exchange.getIn().getHeaders());
    out.setAttachments(exchange.getIn().getAttachments());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:33,代码来源:JoltEndpoint.java

示例14: transform

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
@NotNull
private InputStream transform(@NotNull InputStream content, @NotNull RequestConfiguration configuration) {
    if (StringUtil.isNotEmpty(configuration.getTransform())) {
        List chainrSpecJSON = JsonUtils.jsonToList(configuration.getTransform());
        Chainr chainr = Chainr.fromSpec(chainrSpecJSON);
        Object inputJSON = JsonUtils.jsonToObject(content);
        Object transformedOutput = chainr.transform(inputJSON);

        return new ByteArrayInputStream(JsonUtils.toJsonString(transformedOutput).getBytes(StandardCharsets.UTF_8));
    } else {
        return content;
    }
}
 
开发者ID:grundic,项目名称:teamcity-web-parameters,代码行数:14,代码来源:WebOptionsManagerImpl.java

示例15: migrate

import com.bazaarvoice.jolt.JsonUtils; //导入依赖的package包/类
public String migrate(String oldJSON, int targetVersion) {
    LOGGER.debug("Migrating to version {}: {}", targetVersion, oldJSON);

    Chainr transform = getTransformerFor(targetVersion);
    Object transformedObject = transform.transform(JsonUtils.jsonToMap(oldJSON));
    String transformedJSON = JsonUtils.toJsonString(transformedObject);

    LOGGER.debug("After migration to version {}: {}", targetVersion, transformedJSON);
    return transformedJSON;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:11,代码来源:ConfigRepoMigrator.java


注:本文中的com.bazaarvoice.jolt.JsonUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。