本文整理汇总了Java中com.bazaarvoice.jolt.JsonUtils.jsonToMap方法的典型用法代码示例。如果您正苦于以下问题:Java JsonUtils.jsonToMap方法的具体用法?Java JsonUtils.jsonToMap怎么用?Java JsonUtils.jsonToMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.bazaarvoice.jolt.JsonUtils
的用法示例。
在下文中一共展示了JsonUtils.jsonToMap方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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 );
}
示例2: 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 );
}
示例3: 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-*" )
}
};
}
示例4: getJSONFor
import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
private Map<String, Object> getJSONFor(String fileName) {
try {
String transformJSON = IOUtils.toString(this.getClass().getResourceAsStream(fileName), "UTF-8");
return JsonUtils.jsonToMap(transformJSON);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: inAndOutTestCases
import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@DataProvider
public Object[][] inAndOutTestCases() throws Exception {
return new Object[][] {
{
"Simple Map Test",
SimpleTraversal.newTraversal( "a.b" ),
JsonUtils.jsonToMap( "{ \"a\" : null }" ),
JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : \"tuna\" } }" ),
"tuna"
},
{
"Simple explicit array test",
SimpleTraversal.newTraversal( "a.[1].b" ),
JsonUtils.jsonToMap( "{ \"a\" : null }" ),
JsonUtils.jsonToMap( "{ \"a\" : [ null, { \"b\" : \"tuna\" } ] }" ),
"tuna"
},
{
"Leading Array test",
SimpleTraversal.newTraversal( "[0].a" ),
JsonUtils.jsonToObject( "[ ]" ),
JsonUtils.jsonToObject( "[ { \"a\" : \"b\" } ]" ),
"b"
},
{
"Auto expand array test",
SimpleTraversal.newTraversal( "a.[].b" ),
JsonUtils.jsonToMap( "{ \"a\" : null }" ),
JsonUtils.jsonToMap( "{ \"a\" : [ { \"b\" : null } ] }" ),
null
}
};
}
示例6: doNotUnnecessarilyDieOnImmutableMaps
import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@Test( description = "No exception if we don't try to remove from an ImmutableMap.")
public void doNotUnnecessarilyDieOnImmutableMaps() throws IOException
{
Map expected = JsonUtils.jsonToMap( JsonUtils.toJsonString( top ) );
JoltUtils.removeRecursive( top, "tuna" );
Diffy.Result result = diffy.diff( expected, top );
if (!result.isEmpty()) {
Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString(result.expected) + "\n actual: " + JsonUtils.toJsonString(result.actual));
}
}
示例7: testPolymorphicJacksonSerializationAndDeserialization
import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@Test
public void testPolymorphicJacksonSerializationAndDeserialization()
{
ObjectMapper mapper = new ObjectMapper();
SimpleModule testModule = new SimpleModule("testModule", new Version(1, 0, 0, null, null, null))
.addDeserializer( QueryFilter.class, new QueryFilterDeserializer() )
.addSerializer( LogicalFilter2.class, new LogicalFilter2Serializer() );
mapper.registerModule(testModule);
// Verifying that we can pass in a custom Mapper and create a new JsonUtil
JsonUtil jsonUtil = JsonUtils.customJsonUtil( mapper );
String testFixture = "/jsonUtils/testdomain/two/queryFilter-realAndLogical2.json";
// TEST JsonUtil and our deserialization logic
QueryFilter queryFilter = jsonUtil.classpathToType( testFixture, new TypeReference<QueryFilter>() {} );
// Make sure the hydrated QFilter looks right
Assert.assertTrue( queryFilter instanceof LogicalFilter2 );
Assert.assertEquals( QueryParam.AND, queryFilter.getQueryParam() );
Assert.assertTrue( queryFilter.isLogical() );
Assert.assertEquals( 3, queryFilter.getFilters().size() );
Assert.assertNotNull( queryFilter.getFilters().get( QueryParam.OR ) );
// Make sure one of the top level RealFilters looks right
QueryFilter productIdFilter = queryFilter.getFilters().get( QueryParam.PRODUCTID );
Assert.assertTrue( productIdFilter.isReal() );
Assert.assertEquals( QueryParam.PRODUCTID, productIdFilter.getQueryParam() );
Assert.assertEquals( "Acme-1234", productIdFilter.getValue() );
// Make sure the nested OR looks right
QueryFilter orFilter = queryFilter.getFilters().get( QueryParam.OR );
Assert.assertTrue( orFilter.isLogical() );
Assert.assertEquals( QueryParam.OR, orFilter.getQueryParam() );
Assert.assertEquals( 2, orFilter.getFilters().size() );
// Make sure nested AND looks right
QueryFilter nestedAndFilter = orFilter.getFilters().get( QueryParam.AND );
Assert.assertTrue( nestedAndFilter.isLogical() );
Assert.assertEquals( QueryParam.AND, nestedAndFilter.getQueryParam() );
Assert.assertEquals( 2, nestedAndFilter.getFilters().size() );
// SERIALIZE TO STRING to test serialization logic
String unitTestString = jsonUtil.toJsonString( queryFilter );
// LOAD and Diffy the plain vanilla JSON versions of the documents
Map<String, Object> actual = JsonUtils.jsonToMap( unitTestString );
Map<String, Object> expected = JsonUtils.classpathToMap( testFixture );
// Diffy the vanilla versions
Diffy.Result result = diffy.diff( expected, actual );
if (!result.isEmpty()) {
Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString( result.expected ) + "\n actual: " + JsonUtils.toJsonString( result.actual ) );
}
}
示例8: testPolymorphicJacksonSerializationAndDeserialization
import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@Test
public void testPolymorphicJacksonSerializationAndDeserialization()
{
ObjectMapper mapper = new ObjectMapper();
SimpleModule testModule = new SimpleModule("testModule", new Version(1, 0, 0, null, null, null))
.addDeserializer( QueryFilter4.class, new QueryFilter4Deserializer() );
mapper.registerModule(testModule);
// Verifying that we can pass in a custom Mapper and create a new JsonUtil
JsonUtil jsonUtil = JsonUtils.customJsonUtil( mapper );
String testFixture = "/jsonUtils/testdomain/four/queryFilter-realAndLogical4.json";
// TEST JsonUtil and our deserialization logic
QueryFilter4 queryFilter = jsonUtil.classpathToType( testFixture, new TypeReference<QueryFilter4>() {} );
// Make sure the hydrated QFilter looks right
Assert.assertTrue( queryFilter instanceof LogicalFilter4);
Assert.assertEquals( QueryParam.AND, queryFilter.getQueryParam() );
Assert.assertTrue( queryFilter.isLogical() );
Assert.assertEquals( 3, queryFilter.getFilters().size() );
Assert.assertNotNull( queryFilter.getFilters().get( QueryParam.OR ) );
// Make sure one of the top level RealFilters looks right
QueryFilter4 productIdFilter = queryFilter.getFilters().get( QueryParam.PRODUCTID );
Assert.assertTrue( productIdFilter.isReal() );
Assert.assertTrue( productIdFilter instanceof StringRealFilter4);
StringRealFilter4 stringRealProductIdFilter = (StringRealFilter4) productIdFilter;
Assert.assertEquals( QueryParam.PRODUCTID, stringRealProductIdFilter.getQueryParam() );
Assert.assertEquals( "Acme-1234", stringRealProductIdFilter.getValue() );
// Make sure the nested OR looks right
QueryFilter4 orFilter = queryFilter.getFilters().get( QueryParam.OR );
Assert.assertTrue( orFilter.isLogical() );
Assert.assertEquals( QueryParam.OR, orFilter.getQueryParam() );
Assert.assertEquals( 2, orFilter.getFilters().size() );
// Make sure nested AND looks right
QueryFilter4 nestedAndFilter = orFilter.getFilters().get( QueryParam.AND );
Assert.assertTrue( nestedAndFilter.isLogical() );
Assert.assertEquals( QueryParam.AND, nestedAndFilter.getQueryParam() );
Assert.assertEquals( 2, nestedAndFilter.getFilters().size() );
// SERIALIZE TO STRING to test serialization logic
String unitTestString = jsonUtil.toJsonString( queryFilter );
// LOAD and Diffy the plain vanilla JSON versions of the documents
Map<String, Object> actual = JsonUtils.jsonToMap( unitTestString );
Map<String, Object> expected = JsonUtils.classpathToMap( testFixture );
// Diffy the vanilla versions
Diffy.Result result = diffy.diff( expected, actual );
if (!result.isEmpty()) {
Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString( result.expected ) + "\n actual: " + JsonUtils.toJsonString( result.actual ) );
}
}
示例9: testPolymorphicJacksonSerializationAndDeserialization
import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@Test
public void testPolymorphicJacksonSerializationAndDeserialization()
{
ObjectMapper mapper = new ObjectMapper();
SimpleModule testModule = new SimpleModule("testModule", new Version(1, 0, 0, null, null, null))
.addDeserializer( QueryFilter.class, new QueryFilterDeserializer() );
mapper.registerModule(testModule);
// Verifying that we can pass in a custom Mapper and create a new JsonUtil
JsonUtil jsonUtil = JsonUtils.customJsonUtil( mapper );
String testFixture = "/jsonUtils/testdomain/two/queryFilter-realAndLogical2.json";
// TEST JsonUtil and our deserialization logic
QueryFilter queryFilter = jsonUtil.classpathToType( testFixture, new TypeReference<QueryFilter>() {} );
// Make sure the hydrated QFilter looks right
Assert.assertTrue( queryFilter instanceof LogicalFilter3 );
Assert.assertEquals( QueryParam.AND, queryFilter.getQueryParam() );
Assert.assertTrue( queryFilter.isLogical() );
Assert.assertEquals( 3, queryFilter.getFilters().size() );
Assert.assertNotNull( queryFilter.getFilters().get( QueryParam.OR ) );
// Make sure one of the top level RealFilters looks right
QueryFilter productIdFilter = queryFilter.getFilters().get( QueryParam.PRODUCTID );
Assert.assertTrue( productIdFilter.isReal() );
Assert.assertEquals( QueryParam.PRODUCTID, productIdFilter.getQueryParam() );
Assert.assertEquals( "Acme-1234", productIdFilter.getValue() );
// Make sure the nested OR looks right
QueryFilter orFilter = queryFilter.getFilters().get( QueryParam.OR );
Assert.assertTrue( orFilter.isLogical() );
Assert.assertEquals( QueryParam.OR, orFilter.getQueryParam() );
Assert.assertEquals( 2, orFilter.getFilters().size() );
// Make sure nested AND looks right
QueryFilter nestedAndFilter = orFilter.getFilters().get( QueryParam.AND );
Assert.assertTrue( nestedAndFilter.isLogical() );
Assert.assertEquals( QueryParam.AND, nestedAndFilter.getQueryParam() );
Assert.assertEquals( 2, nestedAndFilter.getFilters().size() );
// SERIALIZE TO STRING to test serialization logic
String unitTestString = jsonUtil.toJsonString( queryFilter );
// LOAD and Diffy the plain vanilla JSON versions of the documents
Map<String, Object> actual = JsonUtils.jsonToMap( unitTestString );
Map<String, Object> expected = JsonUtils.classpathToMap( testFixture );
// Diffy the vanilla versions
Diffy.Result result = diffy.diff( expected, actual );
if (!result.isEmpty()) {
Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString( result.expected ) + "\n actual: " + JsonUtils.toJsonString( result.actual ) );
}
}
示例10: testPolymorphicJacksonSerializationAndDeserialization
import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@Test
public void testPolymorphicJacksonSerializationAndDeserialization()
{
ObjectMapper mapper = new ObjectMapper();
SimpleModule testModule = new SimpleModule("testModule", new Version(1, 0, 0, null, null, null))
.addDeserializer( QueryFilter5.class, new QueryFilter5Deserializer() );
mapper.registerModule(testModule);
// Verifying that we can pass in a custom Mapper and create a new JsonUtil
JsonUtil jsonUtil = JsonUtils.customJsonUtil( mapper );
String testFixture = "/jsonUtils/testdomain/five/queryFilter-realAndLogical5.json";
// TEST JsonUtil and our deserialization logic
QueryFilter5 queryFilter = jsonUtil.classpathToType( testFixture, new TypeReference<QueryFilter5>() {} );
// Make sure the hydrated QFilter looks right
Assert.assertTrue( queryFilter instanceof LogicalFilter5);
LogicalFilter5 andFilter = (LogicalFilter5) queryFilter;
Assert.assertEquals( Operator.AND, andFilter.getOperator() );
Assert.assertNotNull(andFilter.getValues());
Assert.assertEquals(3, andFilter.getValues().size());
// Make sure one of the top level RealFilters looks right
QueryFilter5 productIdFilter = andFilter.getValues().get(1);
Assert.assertTrue( productIdFilter instanceof StringRealFilter5);
StringRealFilter5 stringRealProductIdFilter = (StringRealFilter5) productIdFilter;
Assert.assertEquals( Field.PRODUCTID, stringRealProductIdFilter.getField() );
Assert.assertEquals( Operator.EQ, stringRealProductIdFilter.getOperator() );
Assert.assertEquals( "Acme-1234", stringRealProductIdFilter.getValues().get(0) );
// Make sure the nested OR looks right
QueryFilter5 orFilter = andFilter.getValues().get(2);
Assert.assertTrue( orFilter instanceof LogicalFilter5 );
LogicalFilter5 realOrFilter = (LogicalFilter5) orFilter;
Assert.assertEquals( Operator.OR, realOrFilter.getOperator() );
Assert.assertEquals( 2, realOrFilter.getValues().size() );
// Make sure nested AND looks right
QueryFilter5 nestedAndFilter = realOrFilter.getValues().get(1);
Assert.assertTrue( nestedAndFilter instanceof LogicalFilter5 );
Assert.assertEquals( Operator.AND, nestedAndFilter.getOperator() );
Assert.assertEquals( 3, nestedAndFilter.getValues().size() );
// SERIALIZE TO STRING to test serialization logic
String unitTestString = jsonUtil.toJsonString( queryFilter );
// LOAD and Diffy the plain vanilla JSON versions of the documents
Map<String, Object> actual = JsonUtils.jsonToMap( unitTestString );
Map<String, Object> expected = JsonUtils.classpathToMap( testFixture );
// Diffy the vanilla versions
Diffy.Result result = diffy.diff( expected, actual );
if (!result.isEmpty()) {
Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString( result.expected ) + "\n actual: " + JsonUtils.toJsonString( result.actual ) );
}
}
示例11: testPolymorphicJacksonSerializationAndDeserialization
import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@Test
public void testPolymorphicJacksonSerializationAndDeserialization()
{
ObjectMapper mapper = new ObjectMapper();
SimpleModule testModule = new SimpleModule("testModule", new Version(1, 0, 0, null, null, null))
.addDeserializer( QueryFilter.class, new QueryFilter1Deserializer() );
mapper.registerModule(testModule);
// Verifying that we can pass in a custom Mapper and create a new JsonUtil
JsonUtil jsonUtil = JsonUtils.customJsonUtil( mapper );
String testFixture = "/jsonUtils/testdomain/one/queryFilter-realAndLogical.json";
// TEST JsonUtil and our deserialization logic
QueryFilter queryFilter = jsonUtil.classpathToType( testFixture, new TypeReference<QueryFilter>() {} );
// Make sure the hydrated queryFilter looks right
Assert.assertTrue( queryFilter instanceof LogicalFilter1 );
Assert.assertEquals( QueryParam.AND, queryFilter.getQueryParam() );
Assert.assertTrue( queryFilter.isLogical() );
Assert.assertEquals( 3, queryFilter.getFilters().size() );
Assert.assertNotNull( queryFilter.getFilters().get( QueryParam.OR ) );
// Make sure one of the top level RealFilters looks right
QueryFilter productIdFilter = queryFilter.getFilters().get( QueryParam.PRODUCTID );
Assert.assertTrue( productIdFilter.isReal() );
Assert.assertEquals( QueryParam.PRODUCTID, productIdFilter.getQueryParam() );
Assert.assertEquals( "Acme-1234", productIdFilter.getValue() );
// Make sure the nested OR looks right
QueryFilter orFilter = queryFilter.getFilters().get( QueryParam.OR );
Assert.assertTrue( orFilter.isLogical() );
Assert.assertEquals( QueryParam.OR, orFilter.getQueryParam() );
Assert.assertEquals( 2, orFilter.getFilters().size() );
// Make sure nested AND looks right
QueryFilter nestedAndFilter = orFilter.getFilters().get( QueryParam.AND );
Assert.assertTrue( nestedAndFilter.isLogical() );
Assert.assertEquals( QueryParam.AND, nestedAndFilter.getQueryParam() );
Assert.assertEquals( 2, nestedAndFilter.getFilters().size() );
// SERIALIZE TO STRING to test serialization logic
String unitTestString = jsonUtil.toJsonString( queryFilter );
// LOAD and Diffy the plain vanilla JSON versions of the documents
Map<String, Object> actual = JsonUtils.jsonToMap( unitTestString );
Map<String, Object> expected = JsonUtils.classpathToMap( testFixture );
// Diffy the vanilla versions
Diffy.Result result = diffy.diff( expected, actual );
if (!result.isEmpty()) {
Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString( result.expected ) + "\n actual: " + JsonUtils.toJsonString( result.actual ) );
}
}
示例12: inAndOutTestCases
import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@DataProvider
public Object[][] inAndOutTestCases() throws Exception {
return new Object[][] {
{
"simple place",
Arrays.asList( "tuna" ),
"tuna",
"a.b",
Arrays.asList( "a", "b" ),
JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : \"tuna\" } }" )
},
{
"simple explicit array place",
Arrays.asList( "tuna" ),
null,
"a.b[]",
Arrays.asList( "a", "b", "[]" ),
JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ \"tuna\" ] } }" )
},
{
"simple explicit array place with sub",
Arrays.asList( "tuna" ),
null,
"a.b[].c",
Arrays.asList( "a", "b", "[]", "c" ),
JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ { \"c\" : \"tuna\" } ] } }" )
},
{
"simple array place",
Arrays.asList( "tuna" ),
"tuna",
"a.b.[1]",
Arrays.asList( "a", "b", "1" ),
JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ null, \"tuna\" ] } }" )
},
{
"nested array place",
Arrays.asList( "tuna" ),
"tuna",
"a.b[1].c",
Arrays.asList( "a", "b", "1", "c" ),
JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ null, { \"c\" : \"tuna\" } ] } }" )
},
{
"simple place into write array",
Arrays.asList( "tuna", "marlin" ),
Arrays.asList( "tuna", "marlin" ),
"a.b",
Arrays.asList( "a", "b" ),
JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ \"tuna\", \"marlin\" ] } }" )
},
{
"simple array place with nested write array",
Arrays.asList( "tuna", "marlin" ),
Arrays.asList( "tuna", "marlin" ),
"a.b.[1]",
Arrays.asList( "a", "b", "1" ),
JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ null, [ \"tuna\", \"marlin\" ] ] } }" )
},
{
"nested array place with nested ouptut array",
Arrays.asList( "tuna", "marlin" ),
Arrays.asList( "tuna", "marlin" ),
"a.b.[1].c",
Arrays.asList( "a", "b", "1", "c" ),
JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ null, { \"c\" : [ \"tuna\", \"marlin\"] } ] } }" )
}
};
}
示例13: shiftrTestCases
import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@DataProvider
public Object[][] shiftrTestCases() throws IOException {
return new Object[][] {
{
"Simple * and Reference",
JsonUtils.jsonToMap("{ \"tuna-*-marlin-*\" : { \"rating-*\" : \"&(1,2).&.value\" } }"),
JsonUtils.jsonToMap("{ \"tuna-A-marlin-AAA\" : { \"rating-BBB\" : \"bar\" } }"),
JsonUtils.jsonToMap("{ \"AAA\" : { \"rating-BBB\" : { \"value\" : \"bar\" } } }")
},
{
"Shift to two places",
JsonUtils.jsonToMap("{ \"tuna-*-marlin-*\" : { \"rating-*\" : [ \"&(1,2).&.value\", \"foo\"] } }"),
JsonUtils.jsonToMap("{ \"tuna-A-marlin-AAA\" : { \"rating-BBB\" : \"bar\" } }"),
JsonUtils.jsonToMap("{ \"foo\" : \"bar\", \"AAA\" : { \"rating-BBB\" : { \"value\" : \"bar\" } } }")
},
{
"Or",
JsonUtils.jsonToMap("{ \"tuna|marlin\" : \"&-write\" }"),
JsonUtils.jsonToMap("{ \"tuna\" : \"snapper\" }"),
JsonUtils.jsonToMap("{ \"tuna-write\" : \"snapper\" }")
},
{
"KeyRef",
JsonUtils.jsonToMap("{ \"rating-*\" : { \"&(0,1)\" : { \"match\" : \"&\" } } }"),
JsonUtils.jsonToMap("{ \"rating-a\" : { \"a\" : { \"match\": \"a-match\" }, \"random\" : { \"match\" : \"noise\" } }," +
" \"rating-c\" : { \"c\" : { \"match\": \"c-match\" }, \"random\" : { \"match\" : \"noise\" } } }"),
JsonUtils.jsonToMap("{ \"match\" : [ \"a-match\", \"c-match\" ] }")
},
{
"Complex array write",
JsonUtils.jsonToMap("{ \"tuna-*-marlin-*\" : { \"rating-*\" : \"tuna[&(1,1)].marlin[&(1,2)].&(0,1)\" } }"),
JsonUtils.jsonToMap("{ \"tuna-2-marlin-3\" : { \"rating-BBB\" : \"bar\" }," +
"\"tuna-1-marlin-0\" : { \"rating-AAA\" : \"mahi\" } }"),
JsonUtils.jsonToMap("{ \"tuna\" : [ null, " +
" { \"marlin\" : [ { \"AAA\" : \"mahi\" } ] }, " +
" { \"marlin\" : [ null, null, null, { \"BBB\" : \"bar\" } ] } " +
" ] " +
" }")
}
};
}
示例14: badSpecs
import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@DataProvider
public Object[][] badSpecs() throws IOException {
return new Object[][] {
{
"Null Spec",
null,
},
{
"List Spec",
new ArrayList<>(),
},
{
"Empty spec",
JsonUtils.jsonToMap( "{ }" ),
},
{
"Empty sub-spec",
JsonUtils.javason( "{ 'tuna' : {} }" ),
},
{
"Bad @",
JsonUtils.javason( "{ 'tuna-*-marlin-*' : { '[email protected]' : '&(1,2).&.value' } }" ),
},
{
"RHS @ by itself",
JsonUtils.javason( "{ 'tuna-*-marlin-*' : { 'rating-*' : '&(1,2)[email protected]' } }" ),
},
{
"RHS @ with bad Parens",
JsonUtils.javason( "{ 'tuna-*-marlin-*' : { 'rating-*' : '&(1,2)[email protected](data.&(1,1).value' } }" ),
},
{
"RHS *",
JsonUtils.javason( "{ 'tuna-*-marlin-*' : { 'rating-*' : '&(1,2).*.value' } }" ),
},
{
"RHS $",
JsonUtils.javason( "{ 'tuna-*-marlin-*' : { 'rating-*' : '&(1,2).$.value' } }" ),
},
{
"Two Arrays",
JsonUtils.javason("{ 'tuna-*-marlin-*' : { 'rating-*' : [ '&(1,2).photos[&(0,1)]-subArray[&(1,2)].value', 'foo'] } }"),
},
{
"Can't mix * and & in the same key",
JsonUtils.javason("{ 'tuna-*-marlin-*' : { 'rating-&(1,2)-*' : [ '&(1,2).value', 'foo'] } }"),
},
{
"Don't put negative numbers in array references",
JsonUtils.javason("{ 'tuna' : 'marlin[-1]' }"),
}
};
}