From 2eb6c65c28dcc8a2fd7b7c7544d10d74f73a8e99 Mon Sep 17 00:00:00 2001 From: Neil C Smith Date: Mon, 24 Jun 2024 16:36:58 +0100 Subject: [PATCH] Ensure transient and read-only properties are ignored in serialization. --- .../org/praxislive/code/PropertyControl.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/praxiscore-code/src/main/java/org/praxislive/code/PropertyControl.java b/praxiscore-code/src/main/java/org/praxislive/code/PropertyControl.java index 4e06cbed..438faddf 100644 --- a/praxiscore-code/src/main/java/org/praxislive/code/PropertyControl.java +++ b/praxiscore-code/src/main/java/org/praxislive/code/PropertyControl.java @@ -271,6 +271,7 @@ public static class Descriptor extends ControlDescriptor { private final PropertyControl control; private final Field propertyField; private final boolean synthetic; + private final boolean writable; private Descriptor(String id, int index, @@ -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 @@ -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); + } } }