Why Aren't Some Technically Serializable Input Properties Serializable

Why aren't some technically serializable input properties serializable?

The Specification for input elements defines the exact behaviour. Start reading from here (before that, the DOM interface, attributes and types are defined).

Concise summary (value is defined similarly to checked, so for brevity, I'm going to explain value only).

The "property" value reflects value def,

the "attribute" value reflects the value content attribute def.

  • The attribute defines the default value property (ref). This value is also reflected def by the defaultValue property (ref).
  • When the value attribute is set, then the value property changes (ref) *.

That was worded very concisely. I've skipped an important detail. The specification is very clear at this point, so I'll just quote the dirty value flag section:

Each input element has a boolean dirty value flag. The dirty value
flag must be initially set to false when the element is created, and
must be set to true whenever the user interacts with the control in a
way that changes the value.

The value content attribute gives the default value of the input
element. When the value content attribute is added, set, or removed,
if the control's dirty value flag is false, the user agent must set
the value of the element to the value of the value content attribute,
if there is one, or the empty string otherwise, and then run the
current value sanitization algorithm, if one is defined.

What does [System.SerializableAttribute()] do?

The System.SerializableAttribute specifies to the runtime that the instances of that class can be serialized

Eg. You return an object in a WCF service call. If that object has this attribute and all of the objects inside it are serializable, the runtime will transform that object to JSON or XML, depending on the type of resource the web service returns.

jQuery .val() does not work on html chunk?

value is an atrribute of the input dialog.

Doing .val(...) changes the value property and not the value in the DOM.

See here for the differences between properties and attributes.


If you wanted to see a physical change in the value attribute you could do something like this:

var $obj = jQuery('<div>xx<input type="text" value="" />xx</div>');
$obj.find('input').attr('value','testing');
console.log($obj.html());

Demo: http://jsfiddle.net/maniator/YsZLt/

Disadvantage of making class to Serializable

No, there is no intrinsic overhead simply in being marked as [Serializable]. The only problem I'd have is that BinaryFormatter and NetDataContractSerializer are lousy serializers, and most other serializers aren't interested in this flag (ok, I may be biased)

What is a serializable object?

Normally objects are random access, that is, you can specify any part of an object (property or field) and access that part directly. That's all well and fine if you're using RAM to store an object, because RAM is Random Acess Memory and is therefore suited to the job.

When you need to store your object on a medium that is not traditionally random access, for instance disk, or you need to transfer an object over a stream medium (such as the network) then the object needs to be converted into a form that is suitable to the relevant medium. This conversion process is called serialization, because the structured object is flattened or serialized, making it more amenable to being stored for the long term, or transferred over the network.

Why not just copy the bits comprising the object in RAM to disk, or send it as an opaque blob over the network? ... you may ask. A few issues:

  1. Often the format that the object is stored in memory is proprietary and therefore not suitable for public consumption--the way in which it is stored in memory is optimised for in-memory use.
  2. When an object references other objects, those references only have meaning within the context of the running application. It would not be possible to deserialize the object meaningfully unless during the serialization process, the object graph was walked and serialized accordingly. There may be a need to translate those references into a form that has meaning outside the context of an application instance.
  3. There may be an interoperability requirement between heterogeneous systems, in which case a standard means of representing the object is required (typically some form of XML is chosen for this).

XmlSerializer: serializing a class property as an attribute of a custom subelement

Without changing the type of Value I think it's not possible. You can add the attribute XmlElement(ElementName="Text") on Value but you will obtain a result similar to this:

<MyClass> 
<Text>3</Text>
</MyClass>

Edited:
Another solution can involve XSLT transformation: you can generate the xml using .Net serialization and after apply a xml transformation.

XslTransform myXslTransform = new XslTransform();
myXslTransform.Load(xsltDoc);
myXslTransform.Transform(sourceDoc, resultDoc);

The trasformation of my example should be something like this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<root>
<xsl:apply-templates/>
</root>
</xsl:template>
<xsl:template match="MyClass">
<MyClass>
<Text>
<xsl:attribute name="Value">
<xsl:value-of select="Text"/>
</xsl:attribute>
</Text>
</MyClass>
</xsl:template>
</xsl:stylesheet>

How to make a class JSON serializable

Do you have an idea about the expected output? For example, will this do?

>>> f  = FileItem("/foo/bar")
>>> magic(f)
'{"fname": "/foo/bar"}'

In that case you can merely call json.dumps(f.__dict__).

If you want more customized output then you will have to subclass JSONEncoder and implement your own custom serialization.

For a trivial example, see below.

>>> from json import JSONEncoder
>>> class MyEncoder(JSONEncoder):
def default(self, o):
return o.__dict__

>>> MyEncoder().encode(f)
'{"fname": "/foo/bar"}'

Then you pass this class into the json.dumps() method as cls kwarg:

json.dumps(cls=MyEncoder)

If you also want to decode then you'll have to supply a custom object_hook to the JSONDecoder class. For example:

>>> def from_json(json_object):
if 'fname' in json_object:
return FileItem(json_object['fname'])
>>> f = JSONDecoder(object_hook = from_json).decode('{"fname": "/foo/bar"}')
>>> f
<__main__.FileItem object at 0x9337fac>
>>>

How to serialize message from kafka topic

You are likely facing this issue, @newoneim, because you are using a more recent version of Java.

Recently some CVEs were found in XStream, requiring it to change its approach to serializing.
Previously, it simply de-/serialized everything by reflection, assuming it had the freedom to read everything, now you need to tell XStream which classes it can check through reflection.

This post from AxonIQ's forum explains this predicament in more detail.

Now, what can you do to solve it?
Well, using the JacksonSerializer would be a simple step.
Weirdly enough, I would expect that your configuration would've picked up that you have set the JacksonSerializer for all serializers.

My hunch is that the combination of the Mongo and Kafka Extension from Axon Framework doesn't correctly set the JacksonSerializer on your MongoTokenStore. Note that this is a hunch as we're missing the entire stack trace. However, it's the TokenStore dealing with TrackingTokens. And, it are the KafkaTrackingTokens that fail to serialize properly.

Note that the Mongo Extension from Axon Framework does not have a Spring Boot Auto Configuration. Thus, the settings you're using in your application.properties file aren't automatically picked up by any of the Mongo-extension-specific classes you built. Unless you're wiring them yourself, that is.

Why don't select and textarea value changes get updated upon cloning as with input elements?

I suspect the difference arises because textarea and selects' values are determined by their node content. Modifying the control's value modifies their DOM properties, but not their node content, so when you clone them, the clone has the value of the original element.

You can get around this by updating their node content on the change event:

// textarea
$("textarea").change(function() { $(this).text($(this).val()); });

// select
$("select").change(function() {
var sel = $(this).children(":selected");
$(this.children).not(sel).removeAttr("selected");
sel.attr("selected", "selected");
});

http://jsfiddle.net/emr2w/8/

EDIT:

There are a number of Mozilla bug cases on this (some resolved and some not), but any mention of the actual specs are few and far between. It seems that the the behavior of the value property after a cloneNode() may be a gray area that is not clearly defined in the spec. After all, the purpose of cloneNode() is to clone a DOM node, and not necessarily its object state.

https://bugzilla.mozilla.org/show_bug.cgi?id=197294

https://bugzilla.mozilla.org/show_bug.cgi?id=230307

https://bugzilla.mozilla.org/show_bug.cgi?id=237783



Related Topics



Leave a reply



Submit