RawPath { public static RawPath valueOf(String value) { return new RawPath(value); } private  RawPath(String value); static RawPath valueOf(String value); String getValue(); Path toPath(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); RawPath append(String segments);  }
@Test public void test_new_path_mapping() throws JsonProcessingException { assertThat(om.writeValueAsString(new Foo()), is(equalTo("{}"))); assertThat(om.writeValueAsString(new Foo().setPath(RawPath.valueOf(""))), is(equalTo("{\"path\":\"\"}"))); assertThat(om.writeValueAsString(new Foo().setPath(RawPath.valueOf("foo"))), is(equalTo("{\"path\":\"foo\"}"))); assertThat(om.writeValueAsString(new Foo().setPath(RawPath.valueOf("foo/bar"))), is(equalTo("{\"path\":\"foo/bar\"}"))); assertThat(om.writeValueAsString(new Foo().setPath(RawPath.valueOf("foo\\bar"))), is(equalTo("{\"path\":\"foo\\\\bar\"}"))); assertThat(om.readValue("{\"path\":null}", Foo.class), is(equalTo(new Foo()))); assertThat(om.readValue("{\"path\":\"\"}", Foo.class), is(equalTo(new Foo().setPath(RawPath.valueOf(""))))); assertThat(om.readValue("{\"path\":\"foo\"}", Foo.class), is(equalTo(new Foo().setPath(RawPath.valueOf("foo"))))); assertThat(om.readValue("{\"path\":\"foo/bar\"}", Foo.class), is(equalTo(new Foo().setPath(RawPath.valueOf("foo/bar"))))); assertThat(om.readValue("{\"path\":\"foo\\\\bar\"}", Foo.class), is(equalTo(new Foo().setPath(RawPath.valueOf("foo\\bar"))))); }
@Test public void test_props_and_json() throws JsonProcessingException { Node node = Testing.newTestNode("foo", "localhost").setLogDir(RawPath.valueOf("a\\b")); Cluster cluster = newTestCluster("c", newTestStripe("s").addNode(node)); Properties properties = cluster.toProperties(false, false, true); assertTrue(properties.containsKey("stripe.1.node.1.log-dir")); assertThat(properties.getProperty("stripe.1.node.1.log-dir"), is(equalTo("a\\b"))); String expectedJson = "{\"stripes\":[{\"name\":\"s\",\"nodes\":[{\"hostname\":\"localhost\",\"logDir\":\"a\\\\b\",\"name\":\"foo\",\"uid\":\"jUhhu1kRQd-x6iNgpo9Xyw\"}],\"uid\":\"5Zv3uphiRLavoGZthy7JNg\"}],\"failoverPriority\":\"availability\",\"name\":\"c\",\"uid\":\"YLQguzhRSdS6y5M9vnA5mw\"}"; assertThat(om.writeValueAsString(cluster), om.writeValueAsString(cluster), is(equalTo(expectedJson))); assertThat(om.readValue(expectedJson, Cluster.class), is(equalTo(cluster))); assertThat(om.readValue(expectedJson, Cluster.class).toProperties(false, false, true), is(equalTo(properties))); }