====== Squiggly ====== * [[https://github.com/bohnman/squiggly|bohnman/squiggly: The Squiggly Filter is a Jackson JSON PropertyFilter, which selects properties of an object/list/map using a subset of the Facebook Graph API filtering syntax.]] * [[java:jackson|Java Jackson JSON Library]] 결과 JSON 필드를 동적으로 조정해서 내보낼 수 있다. * [[:rest_api|REST API]] 의 Partial Response 를 구현할 수 있다. * see [[java:jackson:jackson_dynamic_filter|Jackson Dynamic Filter]] * [[https://github.com/bohnman/squiggly/tree/master/examples/spring-boot|squiggly - spring-boot example]] ===== 특수 필터 ===== * nested 는 ''nestedFieldName[field1,field2]'' 형태. * ''ctions[user[lastName]]'' * ''%%**%%'' : 전체 필드 강제 선택 * ''*'' : base field 기준으로만 전체 * ''issue*'' : wildcard * 빈 문자열은 아무 필드도 선택 안함. * ''~iss[a-z]e.*~'' : regex ===== 설정 ===== * classpath root 에 ''squiggly.properties'' 파일로 설정. * ''SquigglyConfig.asMap()''으로 설정정보 읽기 가능. ===== Serializer 사용시 주의 ===== * ''JsonSerializer''에서 ''JsonGenerator'' 사용시 squiggly 가 적용이 안된다. * ''SerializerProvider''를 사용할 것. // Works with Squiggly public class TestSerializer extends JsonSerializer { @Override public void serialize(TestObject value, JsonGenerator jgen, SerializerProvider provider) throws IOException { Map map = new HashMap<>(); map.put("a", value.getA()); map.put("c", value.getC()); provider.defaultSerializeValue(map, jgen); } } ===== 참조 ===== * [[https://dzone.com/articles/dynamically-filter-json-with-jackson-and-squiggly|Dynamically Filter JSON With Jackson and Squiggly - DZone Web Dev]] * [[http://googlecode.blogspot.com/2010/03/making-apis-faster-introducing-partial.html|Making APIs Faster: Introducing Partial Response and Partial Update - The official Google Code blog]] * [[https://developers.facebook.com/docs/graph-api/using-graph-api/#reading|Facebook Graph API fields 선택]] * 또 다른 구현 : https://github.com/pa-media-group/partial-response