iterator() {
82 | int size = sections.size();
83 | return sections.stream()
84 | .map(s -> new Section(s, sections.indexOf(s) == size - 1))
85 | .iterator();
86 | }
87 |
88 | @Override
89 | public boolean equals(Object o) {
90 | if (this == o) return true;
91 | if (o == null || getClass() != o.getClass()) return false;
92 |
93 | Path path = (Path) o;
94 |
95 | if (!sections.equals(path.sections)) return false;
96 | return Objects.equals(attribute, path.attribute);
97 | }
98 |
99 | @Override
100 | public int hashCode() {
101 | int result = sections.hashCode();
102 | result = 31 * result + Objects.hashCode(attribute);
103 | return result;
104 | }
105 |
106 | @Override
107 | public String toString() {
108 | return "/" + String.join("/", sections) + (attribute == null ? "" : "[" + attribute + "]");
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/xjx-serdes/src/main/java/io/jonasg/xjx/serdes/Section.java:
--------------------------------------------------------------------------------
1 | package io.jonasg.xjx.serdes;
2 |
3 | public record Section(String name, boolean isLeaf) {
4 | }
5 |
--------------------------------------------------------------------------------
/xjx-serdes/src/main/java/io/jonasg/xjx/serdes/Tag.java:
--------------------------------------------------------------------------------
1 | package io.jonasg.xjx.serdes;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * The {@code Tag} annotation is used to mark a field for XML serialization and deserialization.
10 | * It provides information about the XML path and optional attributes to be used during serialization and deserialization.
11 | *
12 | * Example XML document:
13 | * {@code
14 | *
15 | * Product 1
16 | * Product 2
17 | * Product 3
18 | *
19 | * }
20 | *
21 | * Example Usage:
22 | * {@code
23 | * @Tag(path = "/Products", items = "Name")
24 | * List productNames;
25 | * }
26 | * In this example, the {@code List} field 'productNames' will be serialized to and deserialized from the XML path "/Products/Name".
27 | *
28 | * Example XML for Serialization:
29 | * {@code
30 | *
31 | * Product 1
32 | * Product 2
33 | * Product 3
34 | *
35 | * }
36 | * In this example, when the {@code List} field 'productNames' is serialized, the generated XML will look like the above representation.
37 | *
38 | * Annotation Usage:
39 | *
40 | * - {@code path}: Specifies the Path expression indicating the location of the XML data for serialization and deserialization.
41 | * - {@code attribute}: Specifies the name of an XML attribute to be used during serialization and deserialization (optional).
42 | * - {@code items}: Specifies additional information for serializing and deserializing items within a collection (optional).
43 | *
44 | */
45 | @Retention(RetentionPolicy.RUNTIME)
46 | @Target({ElementType.TYPE, ElementType.FIELD, ElementType.RECORD_COMPONENT})
47 | public @interface Tag {
48 | /**
49 | * Specifies the Path expression indicating the location of the XML data for serialization and deserialization.
50 | *
51 | * @return The Path expression representing the location of the XML data.
52 | */
53 | String path();
54 |
55 | /**
56 | * Specifies the name of an XML attribute to be used during serialization and deserialization (optional).
57 | *
58 | * @return The name of the XML attribute.
59 | */
60 | String attribute() default "";
61 |
62 | /**
63 | * Specifies additional information for serializing and deserializing items within a collection (optional).
64 | *
65 | * @return Additional information for serializing and deserializing items.
66 | */
67 | String items() default "";
68 | }
69 |
--------------------------------------------------------------------------------
/xjx-serdes/src/main/java/io/jonasg/xjx/serdes/TypeMappers.java:
--------------------------------------------------------------------------------
1 | package io.jonasg.xjx.serdes;
2 |
3 | import io.jonasg.xjx.serdes.deserialize.XjxDeserializationException;
4 | import io.jonasg.xjx.serdes.deserialize.config.XjxConfiguration;
5 |
6 | import java.math.BigDecimal;
7 | import java.time.LocalDate;
8 | import java.time.LocalDateTime;
9 | import java.time.ZonedDateTime;
10 | import java.util.HashSet;
11 | import java.util.List;
12 | import java.util.Set;
13 | import java.util.function.Function;
14 |
15 | public final class TypeMappers {
16 |
17 | static List> DOUBLE_TYPES = List.of(double.class, Double.class);
18 | static List> LONG_TYPES = List.of(long.class, Long.class);
19 | static List> INTEGER_TYPES = List.of(int.class, Integer.class);
20 | static List> CHAR_TYPES = List.of(char.class, Character.class);
21 | static List> BOOLEAN_TYPES = List.of(boolean.class, Boolean.class);
22 |
23 | public static Set> TYPES;
24 |
25 | static {
26 | TYPES = new HashSet<>();
27 | TYPES.addAll(INTEGER_TYPES);
28 | TYPES.addAll(DOUBLE_TYPES);
29 | TYPES.addAll(LONG_TYPES);
30 | TYPES.addAll(CHAR_TYPES);
31 | TYPES.addAll(BOOLEAN_TYPES);
32 | TYPES.add(String.class);
33 | TYPES.add(LocalDate.class);
34 | }
35 |
36 | public static Function