/** * Defines {@link jodd.json.ValueConverter} to use on given path. */ public JsonParser withValueConverter(final String path, final ValueConverter valueConverter) { if (convs == null) { convs = new HashMap<>(); } convs.put(Path.parse(path), valueConverter); return this; }
/** * Defines custom {@link jodd.json.TypeJsonSerializer} for given path. */ public JsonSerializer withSerializer(final String pathString, final TypeJsonSerializer typeJsonSerializer) { if (pathSerializersMap == null) { pathSerializersMap = new HashMap<>(); } pathSerializersMap.put(Path.parse(pathString), typeJsonSerializer); return this; }
/** * Maps a class to given path. For arrays, append <code>values</code> * to the path to specify component type (if not specified by * generics). */ public JsonParser map(final String path, final Class target) { if (path == null) { rootType = target; return this; } if (mappings == null) { mappings = new HashMap<>(); } mappings.put(Path.parse(path), target); return this; }
@Test void testPathMatchingDifferences() { assertTrue(new PathQuery("one.two", true).matches(Path.parse("one"))); assertTrue(new PathQuery("one.two.three", true).matches(Path.parse("one"))); assertTrue(new PathQuery("one.two", true).matches(Path.parse("one.two"))); assertFalse(new PathQuery("one.two", true).matches(Path.parse("one.two.three"))); assertFalse(new PathQuery("one.two", false).matches(Path.parse("one"))); assertTrue(new PathQuery("one.two", false).matches(Path.parse("one.two"))); assertFalse(new PathQuery("one.two", false).matches(Path.parse("one.two.three"))); }
@Test void testPathMatching() { assertTrue(new PathQuery("hello", true).matches(Path.parse("hello"))); assertFalse(new PathQuery("hello", true).matches(Path.parse("boom"))); assertTrue(new PathQuery("hello.world", true).matches(Path.parse("hello.world"))); assertFalse(new PathQuery("hello", true).matches(new Path())); assertTrue(new PathQuery("hello.*.world", true).matches(Path.parse("hello.jupiter.world"))); assertTrue(new PathQuery("hello.*.world", true).matches(Path.parse("hello.earth.moon.world"))); assertTrue(new PathQuery("*.class", true).matches(Path.parse("foo.class"))); assertTrue(new PathQuery("*.class", true).matches(Path.parse("foo.bar.tzar.class"))); assertFalse(new PathQuery("*.class", true).matches(Path.parse("foo.bar.tzar"))); assertTrue(new PathQuery("*", true).matches(Path.parse("a.b.c.d"))); assertTrue(new PathQuery("*.class.*", true).matches(Path.parse("a.b.class.d"))); assertTrue(new PathQuery("*", true).matches(Path.parse("123.asd.234s.fsdre"))); assertTrue(new PathQuery("*.*", true).matches(Path.parse("billy.bong.class.yeker"))); }
assertTrue(Path.parse("one.two.three.four").equals(path)); assertEquals(Path.parse("one.two.three.four").hashCode(), path.hashCode()); assertFalse(Path.parse("one.two.three.four").equals(path)); assertNotEquals(Path.parse("one.two.three.four").hashCode(), path.hashCode()); assertFalse(Path.parse("one.two.thre").equals(path)); assertNotEquals(Path.parse("one.two.thre").hashCode(), path.hashCode());