> This RFE proposes to extend the MXBean framework to define a mapping to
> records.
>
> The MXBean framework already defines a mapping of `CompositeType` to plain
> java objects. Records are a natural representation of CompositeTypes. A
> record can be easily reconstructed from a `CompositeData` through the record
> canonical constructor. A clear advantage of records over plain java objects
> is that the canonical constructor will not need to be annotated in order to
> map composite data property names to constructor parameter names.
>
> With this RFE, here is an example comparing coding a composite type
> `NamedNumber` that consists of an `int` and a `String`, using records and
> using a plain java class. In both case, the `CompositeType` looks like this:
>
> CompositeType(
> "NamedNumber", // typeName
> "NamedNumber", // description
> new String[] {"number", "name"}, // itemNames
> new String[] {"number", "name"}, // itemDescriptions
> new OpenType[] {SimpleType.INTEGER,
> SimpleType.STRING} // itemTypes
> );
>
> The plain Java class needs a public constructor annotated with
> `@ConstructorParameters` annotation:
>
> public class NamedNumber {
> public int getNumber() {return number;}
> public String getName() {return name;}
> @ConstructorParameters({"number", "name"})
> public NamedNumber(int number, String name) {
> this.number = number;
> this.name = name;
> }
> private final int number;
> private final String name;
> }
>
> And the equivalent with a record class:
>
> public record NamedNumber(int number, String name) {}
Daniel Fuchs has updated the pull request with a new target base due to a merge
or a rebase. The incremental webrev excludes the unrelated changes brought in
by the merge/rebase. The pull request contains 13 additional commits since the
last revision:
- Merge
- minor style issue
- minor style issue
- Integrated review feedback
- Improved test
- Moved mapping for records just before Mapping for MXBean interface; Improved
test.
- Merge branch 'master' into mxbeans-8264124
- Minor tweaks. Improved test.
- Merge branch 'master' into mxbeans-8264124
- Integrated review feedback. Updated the section for Mapping to records.
- ... and 3 more: https://git.openjdk.java.net/jdk/compare/5fe7d4c4...257a6ed8
-------------
Changes:
- all: https://git.openjdk.java.net/jdk/pull/3201/files
- new: https://git.openjdk.java.net/jdk/pull/3201/files/a624a763..257a6ed8
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3201&range=06
- incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3201&range=05-06
Stats: 5593 lines in 174 files changed: 3784 ins; 623 del; 1186 mod
Patch: https://git.openjdk.java.net/jdk/pull/3201.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/3201/head:pull/3201
PR: https://git.openjdk.java.net/jdk/pull/3201