Skip to content

Commit

Permalink
doc: improve serialization docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-grgt committed Jan 10, 2024
1 parent 842f65b commit b123066
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ public class Location {
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>°F</Unit>
</Temperature>
<Humidity>
<Value>60</Value>
<Unit>%</Unit>
</Humidity>
<WeatherCondition>Sunny</WeatherCondition>
</CurrentConditions>
<Location>
<City>New York</City>
<Country>USA</Country>
</Location>
<CurrentConditions>
<Temperature>
<Value>75</Value>
<Unit>°F</Unit>
</Temperature>
<Humidity>
<Value>60</Value>
<Unit>%</Unit>
</Humidity>
<WeatherCondition>Sunny</WeatherCondition>
</CurrentConditions>
</WeatherData>""";


Expand All @@ -92,8 +92,8 @@ Each `@Tag` annotation must include a `path` property, using an XPath-like expre

### Path Expressions

Path expressions can be absolute, starting with a slash, representing a path from the root tag to the mapped tag.
Relative paths, without a starting slash, require a parent to be mapped absolutely.
Path expressions can be **absolute**, starting with a slash, representing a path from the root tag to the mapped tag.
**Relative** paths, without a starting slash, require a parent to be mapped absolutely.

```java
import java.math.BigDecimal;
Expand Down Expand Up @@ -167,10 +167,14 @@ When deserializing XML data containing a collection type, the following conventi

```java
public class WeatherData {
// When mapping List or Set the type needs to point to the
// tag containing the repeated elements
@Tag(path = "/WeatherData/Forecasts")
List<Forecast> forecasts;
}

// Top level annoation is required and
// needs to point to an indiviual element that is repeated
@Tag(path = "/WeatherData/Forecasts/Day")
public class Forecast {
// field can be both absolutely as relatively mapped
Expand Down Expand Up @@ -257,8 +261,26 @@ class WeatherData {
}
```

In this example, the country field is serialized to <Country> within the specified path,
and the city field is serialized to <City><Name>.
Given that the above object is fully populated

```java
var weatherData = new WeatherData("Belgium", "Ghent");
```
The serialized result
```java
new XjxSerdes().write(weatherData);
```
Would look like:
```xml
<Weatherdata>
<Location>
<Country>Belgium</Country>
<City>
<Name>Ghent</Name>
</City>
</Location>
</Weatherdata>
```

## Null Fields

Expand Down

0 comments on commit b123066

Please sign in to comment.