2017-02-24 41 views

回答

0

不开箱的,但你可以做到这一点很容易,与杰克逊的POJO变压器 - 请注意,您必须将JSON转换为对象,然后再返回......

private final ObjectMapper mapper = new ObjectMapper(); 

@Transformer(inputChannel = "foo", outputChannel = "bar") 
public String transform(String in) throws Exception { 
// System.out.println(in); 
    String out = new String(
      mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(mapper.readValue(in, Object.class))); 
// System.out.println(out); 
    return out; 
} 

或。 ..

<int:transformer input-channel="foo" output=channel="bar" ref="myJsonPrettyfier" /> 

...如果您使用的是XML。

你甚至可以使用expression;像...

<int:transformer ... 
    expression="new String(@mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(@mapper.readValue(in, Object.class)))" /> 

哪里mapper是为ObjectMapper一个<bean/>

+0

在我的情况下,它已经是一个字符串对象作为Clob从数据库返回,所以你拥有的是完美的。 – haju