3 回答

TA貢獻1821條經(jīng)驗 獲得超6個贊
是什么阻止您編寫從請求 JSON 到規(guī)范化 JSON 的轉(zhuǎn)換器?
我能想到的正常流程是:
Request JSON -> POJO -> POJO with normalized value -> Normalized JSON
所以你的 POJO 看起來像:
public class Filter {
List<FieldFilter> filters;
public static class FieldFilter {
private String field;
private String value;
}
}
現(xiàn)在您將擁有一個轉(zhuǎn)換圖,如:
Map<String, String> fieldNameMapping = new HashMap<>();
fieldNameMapping.put("fName", "firstName");
fieldNameMapping.put("firstName", "firstName");
// The process of populating this map can be done either by a static initializer, or config/properties reader
然后你轉(zhuǎn)換你的 POJO:
Filter filterRequest;
List<FieldFilters> normlizedFilters =
filterReq.getFilters().stream()
.map(f -> new FieldFilter(fieldNameMapping.get(f.getField()), f.getValue())
.collect(toList());
然后將 Filter 類轉(zhuǎn)換為規(guī)范化的 JSON。

TA貢獻1820條經(jīng)驗 獲得超10個贊
我們有一個類似的場景,我們使用的是apache JOLT。如果您想嘗試一些示例,可以參考jolt-demo-online-utility
添加回答
舉報