highsource / jsonix

Powerful XML<->JSON JavaScript mapping library.
BSD 2-Clause "Simplified" License
356 stars 75 forks source link

How to set _dynamic_ default namespace in marshalling process #227

Closed manstis closed 4 years ago

manstis commented 4 years ago

Hi,

I see related issues about default namespaces:

Ideally I'd like to be able to provide the default namespace as an other attribute.

Given the JSON

"otherAttributes":
   {"{http://www.w3.org/2000/xmlns/}":"http://a-dynamic-default-namespace"}

Jsonix.Model.AnyAttributePropertyInfo.marshal.writeAttribute(..) fails as localPart is an empty string that resolve to null in var localPart = name.localPart || name.lp || null (and the same again for prefix later in the same method).

The name object is:

key: "{http://www.w3.org/2000/xmlns/}"
localPart: ""
namespaceURI: "http://www.w3.org/2000/xmlns/"
prefix: ""
string: "{http://www.w3.org/2000/xmlns/}"

The value is:

"http://a-dynamic-default-namespace"

I can use the existing support for namespace prefixes and a mapping of "http://a-dynamic-default-namespace" : "" (where the dynamic value can be passed as a parameter from my code invoking the marshaller) however it'd be nicer (for me) to be able to use other attributes where I currently setup other non-default namespaces and other attributes.

I guess this issue is more of a request and your thoughts are invited.

Thank-you.

Mike

manstis commented 4 years ago

Closing since no response.