Skip to content

Commit

Permalink
doc: enhance attribute mapping documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-grgt committed Mar 4, 2024
1 parent e989e4b commit 2b57b70
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Location {
private Location() {
}

@Tag(path = "City")
@Tag(path = "Country", attribute = "City")
private String City;

@Tag(path = "Country")
Expand All @@ -62,8 +62,7 @@ String document = """
<?xml version="1.0" encoding="UTF-8"?>
<w:WeatherData xmlns:xjx="https://github.com/jonas-grgt/xjx">
<w:Location>
<w:City>New York</w:City>
<w:Country>USA</w:Country>
<w:Country City="New York">USA</w:Country>
</w:Location>
<w:CurrentConditions>
<w:Temperature>
Expand Down Expand Up @@ -148,6 +147,28 @@ class Weather {
### Attributes
Attributes can be mapped using the `attribute` property of the `@Tag` annotation.
```xml
<?xml version="1.0" encoding="UTF-8"?>
<Person>
<Name age="18" sex="MALE">John</Name>
</Person>
```
```java
public class Person {
@Tag(path = "/Person/Name")
String name;
@Tag(path = "/Person/Name", attribute = "sex")
String sex;
@Tag(path = "/Person/Name", attribute = "age")
int age;
}
```
### Collection types
When deserializing an XML document containing repeated elements, it can be mapped onto one of the collection types `List` or `Set`.
Expand Down

0 comments on commit 2b57b70

Please sign in to comment.