Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JavaBeans XML serialization for Quantities #69

Open
arpieb opened this issue Oct 7, 2017 · 4 comments
Open

Support JavaBeans XML serialization for Quantities #69

arpieb opened this issue Oct 7, 2017 · 4 comments

Comments

@arpieb
Copy link

arpieb commented Oct 7, 2017

Hello all! I'm using the UOM-SE library in a simulation project, and am running into a bit of trouble when trying to serialize objects containing ComparableQuantity objects via XMLEncoder. A minimal sample codebase that exhibits the problem (with most of the original classes involved intact) can be found in this gist. The SimulationParameter objects export, but due to exceptions thrown trying to export the UOM objects, no values show up in the XML output. Errors I am seeing are:

java.lang.InstantiationException: tec.uom.se.quantity.NumberQuantity
Continuing ...
java.lang.RuntimeException: failed to evaluate: <unbound>=Class.new();
Continuing ...
java.lang.InstantiationException: tec.uom.se.quantity.DoubleQuantity
Continuing ...
java.lang.RuntimeException: failed to evaluate: <unbound>=Class.new();
Continuing ...

(repeated several times)

I tried to register a DefaultPersistenceDelegate on the XMLEncoder to handle ComparableQuantity by converting the quantity to a string but it is never getting called - and neither does one registered for NumberQuantity. Apparently the DoubleQuantity class is package private so I cannot register a DefaultPersistenceDelegate for it to test. Any suggestions as to how I can get this to work?

Thanks!
-R

@keilw keilw transferred this issue from unitsofmeasurement/uom-se Dec 7, 2019
@andi-huber andi-huber self-assigned this Dec 8, 2019
@andi-huber
Copy link
Member

My intent is to provide a utility class for RI (indriya), where one could just write the following:

ComparableQuantity<Time> q = Quantities.getQuantity(1.0, Units.DAY); // any Quantity

XMLEncoder encoder = new XMLEncoder(...);
EncodingUtil.setupXMLEncoder(encoder); // <-- proposed new utility with indriya
            
encoder.writeObject(q);

@andi-huber andi-huber changed the title Failing on JavaBeans serialization to XML Support JavaBeans XML serialization for Quantities Dec 8, 2019
@andi-huber
Copy link
Member

@keilw where would you like me to put such a utility class EncodingUtil? e.g. the quantities package tech.units.indriya.quantity?

@andi-huber
Copy link
Member

@arpieb feel free to use (copy&paste) the newly proposed class EncodingUtil from associated PR

@andi-huber andi-huber removed their assignment Dec 14, 2019
@keilw
Copy link
Member

keilw commented Dec 16, 2019

I gave it a slightly different name and put it under https://github.com/unitsofmeasurement/uom-clients, have a look, I think "Desktop Client" is good as there might be another approach via JAX-B under https://github.com/unitsofmeasurement/uom-lib similar to the Jackson libraries. Therefore "desktop" involving the "java.desktop" module (not yet applied) sounds OK to me.

Btw, @andi-huber if you're in Vienna over Christmas, I also visit for a couple of days, if you have time, I'd be happy to meet you in person.

@keilw keilw transferred this issue from unitsofmeasurement/indriya Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants