2017-02-24 40 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