Fix immutables generation#3
Merged
Merged
Conversation
- Couldn't find if --json flag could actually make it to release in dmidecode Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
- Remove `@JsonSerialize` annotation as it will be applied individually on entity classes. - Modify `typeAbstract` style to remove the "Abstract" prefix, allowing for cleaner abstract class naming. - Update `typeImmutable` style to add an "Immutable" prefix to generated immutable types. - The current setup leaks the implementations to the public API by default. While mappers need concrete implementation during serialization and deserialization, the final reference must be held by the abstract class itself. - This update to style will allow the abstract classes to have names starting with DMI*, while serialization and deserialization will happen in the mapping layer, with the implemented classes, but they will retain the references of their abstract counterparts which will be returned. Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
…otations - Rename abstract DMI entity classes to their concrete counterparts (e.g., `AbstractDMIProcessor` to `DMIProcessor`). - Add manual `@JsonSerialize` and `@JsonDeserialize` annotations to the renamed classes to specify the immutable implementation for Jackson serialization/deserialization. - Remove example builder code blocks from Javadoc comments as they are no longer relevant to abstract classes. Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
- Replace usage of `Builder()` with `Immutable<EntityName>.Builder()` in various test classes.
- This change aligns the tests with the use of immutable data structures for DMI entities.
- Updated files include:
- `DMIProcessorServiceTest.java`
- `DMISystemServiceTest.java`
- `DMIPortableBatteryServiceTest.java`
- `DMICacheServiceTest.java`
- `DMIBIOSServiceTest.java`
- `DMIBaseboardServiceTest.java`
- `DMIMemoryDeviceServiceTest.java`
- `DMIPhysicalMemoryArrayServiceTest.java`
- `DMISystemSlotsServiceTest.java`
- `DMIChassisServiceTest.java`
- `DMIPortConnectorInformationServiceTest.java`
- `DMIBIOSLanguageServiceTest.java`
Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
- toString() no more returns a pretty-printed JSON. The function has been delegated to `toJson()` instead Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixed leaking of Immutables generated immutable implementations of abstract classes via service classes, to the public API
Type of Change
Bug fix
Before Immutables was introduced, entity classes were not abstract and did not have the
Abstract*prefix either. They were concrete classes and the service classes had these concrete classes as their return type, for exampleList<DMIProcessor> get();.After Immutables was introduced, the entity classes were turned into abstract classes and would have the
Abstract*prefix in their name. Immutables would scan this and create generated immutable implementations after removing theAbstract*prefix. So, an abstract classAbstractDMIProcessor.classwould have an immutable implementation calledDMIProcessor.class. This was fine, but entity naming meant the service classes should have returned the abstract instances. Instead, the return type of the service classes retained the pre-Immutable naming scheme, which meant, service classes would now return generated concrete implementations, instead of the actual abstract entities. This caused a leakage of immutable entities to the public API.It was originally intended for the service classes to de-serialize a JSON to it's immutable instance but return the abstract instance, since all immutable generated sources extend the abstract classes. If there was a need to build a custom instance, something like the following would have been the preferred choice:
where
DMIProcessorrepresents the abstract class andImmutableDMIProcessoris the generated immutable implementation.To achieve this, the
Abstract*prefix from all the abstract classes have been removed, andImmutable*prefix has been added to all generated immutable implementations. Additionally, two Jackson annotations called@JsonSerialize(as = ImmutableSomeName.class)and@JsonDeserialize(as = ImmutableSomeName.class)has been added to all the entity classes.These annotations tell the Jackson mappers in the mapping layer to deserialize or serialize the input JSON as the immutable implementations, but when returning the value to the service layer, which is eventually returned to the user, it should be referenced via the abstract entity only.
JSON -> ImmutableDMIProcessor(mapping layer) -> DMIProcessor(service layer)Obviously, this means you will not be able to access the builder methods, which is intended, because to create your custom builder, you must invoke the Immutable implementations directly. The abstract reference only contains the immutable field values.
Note that this is a BREAKING CHANGE
Breaking Change
toString()in entity classes no longer returns a pretty-printed JSON. The function has been delegated totoJson()instead.