本文整理汇总了Java中com.bazaarvoice.jolt.JsonUtils.jsonToObject方法的典型用法代码示例。如果您正苦于以下问题:Java JsonUtils.jsonToObject方法的具体用法?Java JsonUtils.jsonToObject怎么用?Java JsonUtils.jsonToObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.bazaarvoice.jolt.JsonUtils
的用法示例。
在下文中一共展示了JsonUtils.jsonToObject方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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());
}
示例3: 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;
}
}
示例4: 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
}
};
}
示例5: setup
import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@BeforeClass
@SuppressWarnings("unchecked")
public void setup() throws IOException {
jsonSource = JsonUtils.jsonToObject(jsonSourceString);
jsonSource_empty = JsonUtils.jsonToObject(jsonSourceString_empty);
}