Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 1019 Bytes

README.asciidoc

File metadata and controls

31 lines (21 loc) · 1019 Bytes

Trava (Transit + Java)

Working with transit from Java is often a pain because of deeply nested datastructures that come back from transit. Trava attempts to make life a little easier by providing helper functions to access nested data.

There are things trava doesn’t do yet. For example, assoc in trava won’t work on java.util.List but even in this state I have found it useful. Pull requests are welcome.

Example

{:a {:b {:c 10}}}
//serialized clojure datastructure from above
Map<Keyword,Object> nestedMap = ... ;

List<Keyword> path = Arrays.asList(new KeywordImpl("a"), new KeywordImpl("b"), new KeywordImpl("c"));

Assert.assertEquals(10,Navigator.getIn(nestedMap, path));

//Transform the map to make it like so:
// {:a {:b {:c 10 :d 1}}}
List<Keyword> newPath = Arrays.asList(new KeywordImpl("a"), new KeywordImpl("b"), new KeywordImpl("d"));

nestedMap = Navigator.assocIn(nestedMap, newPath, 1);
Assert.assertEquals(1,Navigator.getIn(nestedMap, newPath));