Skip to content

Commit 8666a86

Browse files
committed
feat: Replace XML with JSON serialization
1 parent 751c2d5 commit 8666a86

File tree

69 files changed

+1814
-959
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1814
-959
lines changed

pom.xml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@
8585
</dependency>
8686
<!-- scope: compile -->
8787
<dependency>
88-
<groupId>jakarta.xml.bind</groupId>
89-
<artifactId>jakarta.xml.bind-api</artifactId>
88+
<groupId>com.fasterxml.jackson.core</groupId>
89+
<artifactId>jackson-annotations</artifactId>
90+
</dependency>
91+
<dependency>
92+
<groupId>com.fasterxml.jackson.core</groupId>
93+
<artifactId>jackson-databind</artifactId>
9094
</dependency>
9195
<dependency>
9296
<groupId>org.apache.commons</groupId>
@@ -101,11 +105,6 @@
101105
<artifactId>log4j-core</artifactId>
102106
</dependency>
103107
<!-- scope: test -->
104-
<dependency>
105-
<groupId>org.glassfish.jaxb</groupId>
106-
<artifactId>jaxb-runtime</artifactId>
107-
<scope>test</scope>
108-
</dependency>
109108
<dependency>
110109
<groupId>org.junit.jupiter</groupId>
111110
<artifactId>junit-jupiter</artifactId>
@@ -177,6 +176,34 @@
177176
</compilerArgs>
178177
</configuration>
179178
</plugin>
179+
<!-- Generate JSON schema from Java classes -->
180+
<plugin>
181+
<groupId>com.github.victools</groupId>
182+
<artifactId>jsonschema-maven-plugin</artifactId>
183+
<version>4.38.0</version>
184+
<configuration>
185+
<classNames>de.rub.nds.modifiablevariable.ModifiableVariable</classNames>
186+
<schemaFilePath>src/main/resources</schemaFilePath>
187+
<schemaFileName>{0}.schema.json</schemaFileName>
188+
<schemaVersion>DRAFT_2020_12</schemaVersion>
189+
<modules>
190+
<module>
191+
<name>Jackson</name>
192+
<options>
193+
<option>RESPECT_JSONPROPERTY_REQUIRED</option>
194+
<option>ALWAYS_REF_SUBTYPES</option>
195+
</options>
196+
</module>
197+
</modules>
198+
</configuration>
199+
<executions>
200+
<execution>
201+
<goals>
202+
<goal>generate</goal>
203+
</goals>
204+
</execution>
205+
</executions>
206+
</plugin>
180207
<!-- Execute unit tests -->
181208
<plugin>
182209
<groupId>org.apache.maven.plugins</groupId>

src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
*/
88
package de.rub.nds.modifiablevariable;
99

10-
import com.fasterxml.jackson.annotation.JsonTypeInfo;
11-
import jakarta.xml.bind.annotation.*;
12-
import java.io.Serializable;
10+
import com.fasterxml.jackson.annotation.*;
11+
import de.rub.nds.modifiablevariable.biginteger.ModifiableBigInteger;
12+
import de.rub.nds.modifiablevariable.bool.ModifiableBoolean;
13+
import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray;
14+
import de.rub.nds.modifiablevariable.integer.ModifiableInteger;
15+
import de.rub.nds.modifiablevariable.length.ModifiableLengthField;
16+
import de.rub.nds.modifiablevariable.longint.ModifiableLong;
17+
import de.rub.nds.modifiablevariable.singlebyte.ModifiableByte;
18+
import de.rub.nds.modifiablevariable.string.ModifiableString;
1319
import java.util.LinkedList;
1420
import java.util.List;
1521
import java.util.stream.Collectors;
@@ -23,24 +29,32 @@
2329
* modified through a chain of {@link VariableModification} operations before being accessed. Each
2430
* subclass represents a specific data type that can be modified at runtime.
2531
*
26-
* <p>The class is defined as transient to allow proper XML serialization with propOrder definition
27-
* in subclasses. See: <a
28-
* href="http://blog.bdoughan.com/2011/06/ignoring-inheritance-with-xmltransient.html">Ignoring
29-
* Inheritance with XmlTransient</a> for details.
30-
*
3132
* @param <E> The type of value this modifiable variable holds (e.g., Integer, String, byte[])
3233
*/
33-
@XmlTransient
34-
@XmlAccessorType(XmlAccessType.FIELD)
35-
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
36-
public abstract class ModifiableVariable<E> implements Serializable {
34+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type")
35+
@JsonSubTypes({
36+
@JsonSubTypes.Type(name = "BigInteger", value = ModifiableBigInteger.class),
37+
@JsonSubTypes.Type(name = "Boolean", value = ModifiableBoolean.class),
38+
@JsonSubTypes.Type(name = "ByteArray", value = ModifiableByteArray.class),
39+
@JsonSubTypes.Type(name = "Integer", value = ModifiableInteger.class),
40+
@JsonSubTypes.Type(name = "LengthField", value = ModifiableLengthField.class),
41+
@JsonSubTypes.Type(name = "Long", value = ModifiableLong.class),
42+
@JsonSubTypes.Type(name = "Byte", value = ModifiableByte.class),
43+
@JsonSubTypes.Type(name = "String", value = ModifiableString.class),
44+
})
45+
@JsonAutoDetect(
46+
fieldVisibility = JsonAutoDetect.Visibility.ANY,
47+
getterVisibility = JsonAutoDetect.Visibility.NONE,
48+
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
49+
setterVisibility = JsonAutoDetect.Visibility.NONE)
50+
public abstract class ModifiableVariable<E> {
3751

3852
/** The list of modifications that will be applied to the original value when accessed */
39-
@XmlElementWrapper
40-
@XmlAnyElement(lax = true)
53+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
4154
private LinkedList<VariableModification<E>> modifications;
4255

4356
/** The expected value for assertion validation */
57+
@JsonInclude(JsonInclude.Include.NON_NULL)
4458
protected E assertEquals;
4559

4660
/** Default constructor that creates an empty modifiable variable. */

src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
import de.rub.nds.modifiablevariable.util.ArrayConverter;
1111
import de.rub.nds.modifiablevariable.util.ReflectionHelper;
12-
import jakarta.xml.bind.annotation.XmlType;
13-
import java.io.Serializable;
1412
import java.lang.reflect.Field;
1513
import java.lang.reflect.Modifier;
1614
import java.util.LinkedList;
@@ -35,11 +33,8 @@
3533
*
3634
* <p>This class is the backbone of the modifiable variable framework, as it allows for systematic
3735
* manipulation and inspection of protocol data structures that contain modifiable variables.
38-
*
39-
* <p>Classes that extend this base class can be serialized to XML using JAXB.
4036
*/
41-
@XmlType(name = "ModVarHolder")
42-
public abstract class ModifiableVariableHolder implements Serializable {
37+
public abstract class ModifiableVariableHolder {
4338

4439
/** Logger for this class */
4540
private static final Logger LOGGER = LogManager.getLogger();

src/main/java/de/rub/nds/modifiablevariable/VariableModification.java

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@
99

1010
import static de.rub.nds.modifiablevariable.util.StringUtil.backslashEscapeString;
1111

12+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
13+
import com.fasterxml.jackson.annotation.JsonSubTypes;
1214
import com.fasterxml.jackson.annotation.JsonTypeInfo;
15+
import de.rub.nds.modifiablevariable.biginteger.*;
16+
import de.rub.nds.modifiablevariable.bool.BooleanExplicitValueModification;
17+
import de.rub.nds.modifiablevariable.bool.BooleanToggleModification;
18+
import de.rub.nds.modifiablevariable.bytearray.*;
19+
import de.rub.nds.modifiablevariable.integer.*;
20+
import de.rub.nds.modifiablevariable.longint.*;
21+
import de.rub.nds.modifiablevariable.singlebyte.ByteAddModification;
22+
import de.rub.nds.modifiablevariable.singlebyte.ByteExplicitValueModification;
23+
import de.rub.nds.modifiablevariable.singlebyte.ByteSubtractModification;
24+
import de.rub.nds.modifiablevariable.singlebyte.ByteXorModification;
25+
import de.rub.nds.modifiablevariable.string.*;
1326
import de.rub.nds.modifiablevariable.util.ArrayConverter;
14-
import jakarta.xml.bind.annotation.XmlAccessType;
15-
import jakarta.xml.bind.annotation.XmlAccessorType;
16-
import jakarta.xml.bind.annotation.XmlTransient;
17-
import java.io.Serializable;
1827
import org.apache.logging.log4j.LogManager;
1928
import org.apache.logging.log4j.Logger;
2029

@@ -44,10 +53,73 @@
4453
*
4554
* @param <E> The type of value this modification operates on
4655
*/
47-
@XmlTransient
48-
@XmlAccessorType(XmlAccessType.FIELD)
49-
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
50-
public abstract class VariableModification<E> implements Serializable {
56+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type")
57+
@JsonSubTypes({
58+
@JsonSubTypes.Type(name = "BigIntegerAdd", value = BigIntegerAddModification.class),
59+
@JsonSubTypes.Type(
60+
name = "BigIntegerExplicitValue",
61+
value = BigIntegerExplicitValueModification.class),
62+
@JsonSubTypes.Type(name = "BigIntegerMultiply", value = BigIntegerMultiplyModification.class),
63+
@JsonSubTypes.Type(name = "BigIntegerShiftLeft", value = BigIntegerShiftLeftModification.class),
64+
@JsonSubTypes.Type(
65+
name = "BigIntegerShiftRight",
66+
value = BigIntegerShiftRightModification.class),
67+
@JsonSubTypes.Type(name = "BigIntegerSubtract", value = BigIntegerSubtractModification.class),
68+
@JsonSubTypes.Type(name = "BigIntegerXor", value = BigIntegerXorModification.class),
69+
@JsonSubTypes.Type(
70+
name = "BooleanExplicitValue",
71+
value = BooleanExplicitValueModification.class),
72+
@JsonSubTypes.Type(name = "BooleanToggle", value = BooleanToggleModification.class),
73+
@JsonSubTypes.Type(
74+
name = "ByteArrayAppendValue",
75+
value = ByteArrayAppendValueModification.class),
76+
@JsonSubTypes.Type(name = "ByteArrayDelete", value = ByteArrayDeleteModification.class),
77+
@JsonSubTypes.Type(name = "ByteArrayDuplicate", value = ByteArrayDuplicateModification.class),
78+
@JsonSubTypes.Type(
79+
name = "ByteArrayExplicitValue",
80+
value = ByteArrayExplicitValueModification.class),
81+
@JsonSubTypes.Type(
82+
name = "ByteArrayInsertValue",
83+
value = ByteArrayInsertValueModification.class),
84+
@JsonSubTypes.Type(
85+
name = "ByteArrayPrependValue",
86+
value = ByteArrayPrependValueModification.class),
87+
@JsonSubTypes.Type(name = "ByteArrayShuffle", value = ByteArrayShuffleModification.class),
88+
@JsonSubTypes.Type(name = "ByteArrayXor", value = ByteArrayXorModification.class),
89+
@JsonSubTypes.Type(name = "IntegerAdd", value = IntegerAddModification.class),
90+
@JsonSubTypes.Type(
91+
name = "IntegerExplicitValue",
92+
value = IntegerExplicitValueModification.class),
93+
@JsonSubTypes.Type(name = "IntegerMultiply", value = IntegerMultiplyModification.class),
94+
@JsonSubTypes.Type(name = "IntegerShiftLeft", value = IntegerShiftLeftModification.class),
95+
@JsonSubTypes.Type(name = "IntegerShiftRight", value = IntegerShiftRightModification.class),
96+
@JsonSubTypes.Type(name = "IntegerSubtract", value = IntegerSubtractModification.class),
97+
@JsonSubTypes.Type(name = "IntegerSwapEndian", value = IntegerSwapEndianModification.class),
98+
@JsonSubTypes.Type(name = "IntegerXor", value = IntegerXorModification.class),
99+
@JsonSubTypes.Type(name = "LongAdd", value = LongAddModification.class),
100+
@JsonSubTypes.Type(name = "LongExplicitValue", value = LongExplicitValueModification.class),
101+
@JsonSubTypes.Type(name = "LongMultiply", value = LongMultiplyModification.class),
102+
@JsonSubTypes.Type(name = "LongShiftLeft", value = LongShiftLeftModification.class),
103+
@JsonSubTypes.Type(name = "LongShiftRight", value = LongShiftRightModification.class),
104+
@JsonSubTypes.Type(name = "LongSubtract", value = LongSubtractModification.class),
105+
@JsonSubTypes.Type(name = "LongSwapEndian", value = LongSwapEndianModification.class),
106+
@JsonSubTypes.Type(name = "LongXor", value = LongXorModification.class),
107+
@JsonSubTypes.Type(name = "ByteAdd", value = ByteAddModification.class),
108+
@JsonSubTypes.Type(name = "ByteExplicitValue", value = ByteExplicitValueModification.class),
109+
@JsonSubTypes.Type(name = "ByteSubtract", value = ByteSubtractModification.class),
110+
@JsonSubTypes.Type(name = "ByteXor", value = ByteXorModification.class),
111+
@JsonSubTypes.Type(name = "StringAppendValue", value = StringAppendValueModification.class),
112+
@JsonSubTypes.Type(name = "StringDelete", value = StringDeleteModification.class),
113+
@JsonSubTypes.Type(name = "StringExplicitValue", value = StringExplicitValueModification.class),
114+
@JsonSubTypes.Type(name = "StringInsertValue", value = StringInsertValueModification.class),
115+
@JsonSubTypes.Type(name = "StringPrependValue", value = StringPrependValueModification.class),
116+
})
117+
@JsonAutoDetect(
118+
fieldVisibility = JsonAutoDetect.Visibility.ANY,
119+
getterVisibility = JsonAutoDetect.Visibility.NONE,
120+
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
121+
setterVisibility = JsonAutoDetect.Visibility.NONE)
122+
public abstract class VariableModification<E> {
51123

52124
/** Logger for debugging modification applications */
53125
protected static final Logger LOGGER = LogManager.getLogger(VariableModification.class);

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
package de.rub.nds.modifiablevariable.biginteger;
99

10+
import com.fasterxml.jackson.annotation.JsonProperty;
1011
import de.rub.nds.modifiablevariable.VariableModification;
11-
import jakarta.xml.bind.annotation.XmlRootElement;
1212
import java.math.BigInteger;
1313
import java.util.Objects;
1414

@@ -19,10 +19,10 @@
1919
* It can be used to increment or decrement BigInteger values at runtime, which is particularly
2020
* useful for manipulating large integer values like those used in cryptographic operations.
2121
*/
22-
@XmlRootElement
2322
public class BigIntegerAddModification extends VariableModification<BigInteger> {
2423

2524
/** The value to add to the original BigInteger */
25+
@JsonProperty(required = true)
2626
private BigInteger summand;
2727

2828
/** Default constructor for serialization. */

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
package de.rub.nds.modifiablevariable.biginteger;
99

10+
import com.fasterxml.jackson.annotation.JsonProperty;
1011
import de.rub.nds.modifiablevariable.VariableModification;
11-
import jakarta.xml.bind.annotation.XmlRootElement;
1212
import java.math.BigInteger;
1313
import java.util.Objects;
1414

@@ -21,10 +21,10 @@
2121
*
2222
* @see ModifiableBigInteger
2323
*/
24-
@XmlRootElement
2524
public class BigIntegerExplicitValueModification extends VariableModification<BigInteger> {
2625

2726
/** The explicit value that will replace the original value */
27+
@JsonProperty(required = true)
2828
private BigInteger explicitValue;
2929

3030
/** Default constructor for serialization. */

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
package de.rub.nds.modifiablevariable.biginteger;
99

10+
import com.fasterxml.jackson.annotation.JsonProperty;
1011
import de.rub.nds.modifiablevariable.VariableModification;
11-
import jakarta.xml.bind.annotation.XmlRootElement;
1212
import java.math.BigInteger;
1313
import java.util.Objects;
1414

@@ -20,10 +20,10 @@
2020
*
2121
* @see ModifiableBigInteger
2222
*/
23-
@XmlRootElement
2423
public class BigIntegerMultiplyModification extends VariableModification<BigInteger> {
2524

2625
/** The factor to multiply by */
26+
@JsonProperty(required = true)
2727
private BigInteger factor;
2828

2929
/** Default constructor for serialization. */

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
package de.rub.nds.modifiablevariable.biginteger;
99

10+
import com.fasterxml.jackson.annotation.JsonProperty;
1011
import de.rub.nds.modifiablevariable.VariableModification;
11-
import jakarta.xml.bind.annotation.XmlRootElement;
1212
import java.math.BigInteger;
1313

1414
/**
@@ -21,10 +21,10 @@
2121
* @see ModifiableBigInteger
2222
* @see BigIntegerShiftRightModification
2323
*/
24-
@XmlRootElement
2524
public class BigIntegerShiftLeftModification extends VariableModification<BigInteger> {
2625

2726
/** The number of bits to shift left */
27+
@JsonProperty(required = true)
2828
private int shift;
2929

3030
/** Default constructor for serialization. */

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
package de.rub.nds.modifiablevariable.biginteger;
99

10+
import com.fasterxml.jackson.annotation.JsonProperty;
1011
import de.rub.nds.modifiablevariable.VariableModification;
11-
import jakarta.xml.bind.annotation.XmlRootElement;
1212
import java.math.BigInteger;
1313

1414
/**
@@ -21,10 +21,10 @@
2121
* @see BigIntegerShiftLeftModification
2222
* @see ModifiableBigInteger
2323
*/
24-
@XmlRootElement
2524
public class BigIntegerShiftRightModification extends VariableModification<BigInteger> {
2625

2726
/** The number of bit positions to shift right */
27+
@JsonProperty(required = true)
2828
private int shift;
2929

3030
/** Default constructor for serialization. */

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
package de.rub.nds.modifiablevariable.biginteger;
99

10+
import com.fasterxml.jackson.annotation.JsonProperty;
1011
import de.rub.nds.modifiablevariable.VariableModification;
11-
import jakarta.xml.bind.annotation.XmlRootElement;
1212
import java.math.BigInteger;
1313
import java.util.Objects;
1414

@@ -20,10 +20,10 @@
2020
*
2121
* @see ModifiableBigInteger
2222
*/
23-
@XmlRootElement
2423
public class BigIntegerSubtractModification extends VariableModification<BigInteger> {
2524

2625
/** The value to subtract from the original BigInteger */
26+
@JsonProperty(required = true)
2727
private BigInteger subtrahend;
2828

2929
/** Default constructor for serialization. */

0 commit comments

Comments
 (0)