Extensions: How to control serialisation?

Welcome to Wisej Support.
Questions, suggestions and plain old bugs - are all welcome here!
Answered
0
0

I’m trying to add scale options into the chart.js extension. As part of this I need some properties to only be serialised if they are not a specific value. I’ve tried adding a ShouldSerialise method but there is obviously some other trick as the data still appears.

In a similar vein is there anyway to tell wisej not to serialise a property whose value is null?

Nic

PS: I realised I made an error in my chartjs extension changes so the time scale type won’t work correctly just yet in the code I uploaded. I’ll upload the fixed version when I have also sorted out the scale options.

 

 

 

 

  • You must to post comments
Best Answer
0
0

Got it. Wisej serializes .NET object to JSON strings and JSON strings back to Wisej.Core.DynamicObject instances. Null values are serializes too since they are valid values, otherwise you’d never be able to set a property to null  in the client.

You can remove a property from a wisej dynamic object by calling config.Remove(“property name”).

For the designer serialization, in case you are overriding an inherited property (like it’s probably the case with the ScaleType :)), you have to shadow the property or the ShouldSerialize* and Reset* methods won’t work. See my other reply to the ChartJS issue with attachment.

/Luca

 

  • You must to post comments
0
0

Hi Luca,

Thanks for clarifying. I think I was confused between the serialisation options for the editor and how WiseJ serialises options for the java object. I can see now why what I was doing didn’t work but I still can’t figure out how I stop WiseJ putting properties with null values into the config for chartjs when it calls

script = script.Replace(“$config”, config.ToString());

I have a property that should not be output if it is null and at present it is always output but with a value of null (i.e {“time”: null}).

Thanks

Nic

  • You must to post comments
0
0

Hi Nic,

The serialization in Wisej is entirely based on System.ComponentModel. You can control what happens to a property at design time using:

https://msdn.microsoft.com/en-us/library/system.componentmodel.designerserializationvisibilityattribute(v=vs.110).aspx

 

[Browsable] hide/show the  property in the properties panel

[DesignerSerializationVisibility] exclude/include, or whether to serialize the property value or its content.

[DefaultValue] this is alternative to the private bool ShouldSerialize[PropertyName] and private void Reset[PropertyName] methods.

[Editor], [TypeConverter] to determine the editor and the conversion/serialization to/from a string or a CodeDom definition.

HTH

Best,

Luca

 

  • You must to post comments
Showing 3 results
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Attachment
File Name Size
There are currently no files uploaded.
Maximum number of files 1, maximum file size 3.9MB.
Supported file formats: zip pdf gif jpg bmp png cs vb theme json