-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Improve JSON serialization with ModifiableVariable #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
To be honest - I am not so sure about this one. Like - point1 you are making is not really relevant for us - we are not storing billions and trillions of XML files - so spending a few more bytes on tags is not really worth fixing. Point 2 i dont understand. Point 3: We had this for XML - we removed it cause it was making our lives miserable. Point 4 is nice - but I dont think this is that much related to XML but just to the framework. For me, this is a bit like switching from Java to kotlin - like - i see some benefits - but its not really fixing a real issue we are facing that I would say its worth it to switch. Like - at the moment we kind of have both JSON and XML cause MongoDB in the crawler prefers JSON - but the next usecase is some different dataformat... the only real benefit is that we could drop one of the two imho. Maybe we can discuss in the next meeting |
Yes, we should discuss this. I consider this PR mandatory to allow a soft switch towards Protocol-Attacker as Jakarta prevents us from introducing common superinterfaces for types used in the configuration and workflow files. I came across this issue while trying to introduce a common |
Minimal example: public abstract class Config {
private WorkflowTraceType workflowTraceType;
}
public class TlsConfig extends Config { }
public interface WorkflowTraceType { }
public enum TlsWorkflowTraceType implements WorkflowTraceType {
DTLS
} With Jakarta, it is not possible to serialize |
From the documentation:
|
what do you mean? |
Ah I understand now 🤔 |
Ok that convinces me - the alternatives are not looking great - I dont have strong opinions on XML vs Json - for me its good enough when you can machine read it. Another big concern I have is with the "how" we use it. Cause right now, it looks like we need to add a lot of annotations as seen in your PR - which I really would want to try to avoid. Also looks like we are starring at a lot of refactoring in the downstream project with this PR that will probably keep us busy for weeks. |
Regarding annotations, most of them are there to allow for a less verbose JSON serialization / deserialization. Currently, my PR uses the following annotations:
On the other hand, |
In the meantime, I also thought about how we can migrate all projects to Jackson. The most promising migration path from my point of view would be to keep XML annotations in place for now, and simply add the Jackson annotations on top of it. Once all projects are updated to use Jackson instead of Jakarta, we can simply remove XML-related annotations and dependencies in all projects all at once. This would allow us to migrate to Jackson step-by-step without disrupting BOM updates. |
sure
This I want to avoid at all cost. Schema I am willing to drop for this.
Can we configure this globally instead?
We should do that.
I assume this mostly affects modvar - so it should be fine. |
Okay, I tested a few approaches. It seems that we can either have a correct schema or no |
8666a86
to
40a1e33
Compare
People were constantly forgetting to add types, you sometimes had the same "style" of annotations at multiple points in the code base and then had to search all over the place where you have to add the new class. Additionally, its not flexible when you want to add more classes from the outside. |
d25d285
to
8cc3c7b
Compare
8cc3c7b
to
475dd26
Compare
This was an issue with Jakarta, but not Jackson. Jackson requires this annotation exactly once in the base class and not in multiple locations throughout the code base. With Jakarta, you were required to denote possible subtypes in all classes using the supertype. So, this should be a non-issue.
While we statically list those subtypes to be included in the schema, this does not mean that you cannot include additional named types from the outside. The object mapper provides one with the ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new ModifiableVariableModule());
mapper.registerSubtypes(new NamedType(ModifiableShort.class, "Short"));
// Now, mapper can (de-)serialize ModifiableShort as a subtype of ModifiableVariable |
but if I include additional types from the outside I cannot use the schema anymore? If I can - why cant i just directly add the types from the outside without listing them |
Cause - like if I move "DataContainer" or something to protocol-attacker - I cannot add these annotations anymore anyways cause all the implementations are outside of protocol-attacker |
We can set a default inclusion globally, if we want to. However, this may result in unwanted exclusions where we want to explicitly include null or empty values. I only included the annotation where I deemed exclusion of null / empty values okay to do. The better way might be to remove these annotations altogether. |
This is a limitation of the schema generation library I used here. The Jackson module for this library correctly picks up |
c0bb9e4
to
bdf4fde
Compare
Okay, I think I found a decent solution for the As an added bonus, the schema is now more precise because I implemented a check to verify that subtypes match the bound types of the declared type. Now, for every type of ModifiableVariables, the modifications only list the ones actually allowed (rather than all). For now, I kept all other annotations in place. |
This PR replaces the cumbersome and verbose XML serialization of ModifiableVariable objects using Jakarta with JSON serialization using Jackson. It is one of several PRs with the goal of migrating TLS-Attacker to a full JSON serialization. Jackson is already being used, for example, by the Scanner-Core for serializing scanner results. This change has become necessary for various reasons that limit TLS-Attacker and related projects. Among others, those are:
mvn install
is run.ModifiableVariableModule
module which configures Jackson's object mapper for (de-)serializing modifiable variables.The resulting JSON schema for a
ModifiableVariable
instance can be found undersrc/main/resources/ModifiableVariable.schema.json
.Example (will return a
ModifiableBigInteger
that computes (originalValue + 10) * 5):