Skip to content

Commit

Permalink
doc: add namespace to example snippet
Browse files Browse the repository at this point in the history
Add test to support this.
  • Loading branch information
jonas-grgt committed Mar 4, 2024
1 parent 7abd79b commit 5461751
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ public class Location {
```java
String document = """
<?xml version="1.0" encoding="UTF-8"?>
<WeatherData>
<Location>
<City>New York</City>
<Country>USA</Country>
</Location>
<CurrentConditions>
<Temperature>
<Value>75</Value>
<Unit><![CDATA[°F]]></Unit>
</Temperature>
<Humidity>
<Value>60</Value>
<Unit>%</Unit>
</Humidity>
<WeatherCondition>Sunny</WeatherCondition>
</CurrentConditions>
</WeatherData>""";
<w:WeatherData xmlns:xjx="https://github.com/jonas-grgt/xjx">
<w:Location>
<w:City>New York</w:City>
<w:Country>USA</w:Country>
</w:Location>
<w:CurrentConditions>
<w:Temperature>
<w:Value>75</Value>
<w:Unit><![CDATAF]]></w:Unit>
</w:Temperature>
<w:Humidity>
<w:Value>60</w:Value>
<w:Unit>%</w:Unit>
</w:Humidity>
<w:WeatherCondition>Sunny</w:WeatherCondition>
</w:CurrentConditions>
</w:WeatherData>""";
var xjx = new XjxSerdes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,31 @@ static class AbsoluteRootMappingHolder {
@Tag(path = "/DataTypes/Double")
Double Double;
}

@Test
void namespaceSupport() {
// given
String data = """
<?xml version="1.0" encoding="UTF-8"?>
<xjx:Tables xmlns:xjx="https://github.com/jonas-grgt/xjx">
<xjx:TableA>5.7</xjx:TableA>
<TableB>TableB</TableB>
</xjx:Tables>
""";

// when
var holder = new XjxSerdes().read(data, NamespaceHolder.class);

// then
assertThat(holder.tableA).isEqualTo(5.7D);
assertThat(holder.tableB).isEqualTo("TableB");
}

static class NamespaceHolder {
@Tag(path = "/Tables/TableA")
Double tableA;

@Tag(path = "/Tables/TableB")
String tableB;
}
}

0 comments on commit 5461751

Please sign in to comment.