Skip to content

Commit

Permalink
Ensure transient and read-only properties are ignored in serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcsmith-net committed Jun 24, 2024
1 parent 9b3d2ca commit 2eb6c65
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public static class Descriptor extends ControlDescriptor<Descriptor> {
private final PropertyControl control;
private final Field propertyField;
private final boolean synthetic;
private final boolean writable;

private Descriptor(String id,
int index,
Expand All @@ -282,15 +283,22 @@ private Descriptor(String id,
) {
super(Descriptor.class, id, Category.Property, index);
control = new PropertyControl(info, binding, onChange, onError);
this.propertyField = field;
this.synthetic = false;
propertyField = field;
synthetic = false;
if (info.controlType() == ControlInfo.Type.ReadOnlyProperty
|| info.properties().getBoolean(ControlInfo.KEY_TRANSIENT, false)) {
writable = false;
} else {
writable = true;
}
}

private Descriptor(String id, int index, Binding binding, Field field) {
super(Descriptor.class, id, Category.Synthetic, index);
control = new PropertyControl(null, binding, null, null);
propertyField = field;
this.synthetic = true;
synthetic = true;
writable = false;
}

@Override
Expand Down Expand Up @@ -342,10 +350,12 @@ public void onStop() {

@Override
public void write(TreeWriter writer) {
Value val = control.get();
Value def = control.binding.getDefaultValue();
if (val != null && !val.equals(def)) {
writer.writeProperty(id(), val);
if (writable) {
Value val = control.get();
Value def = control.binding.getDefaultValue();
if (val != null && !val.equals(def)) {
writer.writeProperty(id(), val);
}
}
}

Expand Down

0 comments on commit 2eb6c65

Please sign in to comment.