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

Serialization of units with "per square" content #68

Closed
fawidmer opened this issue Mar 19, 2021 · 4 comments
Closed

Serialization of units with "per square" content #68

fawidmer opened this issue Mar 19, 2021 · 4 comments
Milestone

Comments

@fawidmer
Copy link

The following minimum example displays:

"m2"
"m/s"
"V2/Ohm"
"Ohm/V"

However, I'd expect something like:

"m2"
"m/s2"
"V2/Ohm"
"Ohm/V2"

It seems like this issue only happens for units with a negative exponent. Units like square meter seem to work fine.

Our dependencies:

<dependency>
    <groupId>tech.units</groupId>
    <artifactId>indriya</artifactId>
    <version>2.0.4</version>
</dependency>

<dependency>
    <groupId>tech.uom.lib</groupId>
    <artifactId>uom-lib-jackson</artifactId>
    <version>2.0.1</version>
</dependency>

Sample code:

import javax.measure.Unit;
import javax.measure.quantity.Acceleration;
import javax.measure.quantity.Area;

import org.junit.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import tech.units.indriya.unit.Units;
import tech.uom.lib.jackson.UnitJacksonModule;

public class TempTest {

    @Test
    public void test() throws JsonProcessingException {
        Unit<Area> areaUnit = Units.SQUARE_METRE;
        Unit<Acceleration> accelUnit = Units.METRE_PER_SQUARE_SECOND;
        Unit<?> composedUnit = Units.VOLT.pow(2).divide(Units.OHM);
        Unit<?> composedUnitInverted = composedUnit.inverse();

        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new UnitJacksonModule());

        System.out.println(mapper.writeValueAsString(areaUnit));
        System.out.println(mapper.writeValueAsString(accelUnit));
        System.out.println(mapper.writeValueAsString(composedUnit));
        System.out.println(mapper.writeValueAsString(composedUnitInverted));
    }

}
@keilw keilw added the analysis label Apr 6, 2021
@keilw keilw added the json label May 11, 2021
@fawidmer
Copy link
Author

@keilw: I was just checking the status of this issue and was very happy to see that you recently added some labels. Please feel free to contact me at any time if you need further information!

@keilw
Copy link
Member

keilw commented May 14, 2021

@fawidmer Basically I added some more labels like JSON for both the Jackson and Yasson (Jakarta JSON Binding) modules. There also is a RI ticket unitsofmeasurement/indriya#352 which I recently transferred from the API because it could be related to Indriya, but it also includes this library, so not completely impossible they have something to do with each other.

@keilw keilw added this to the 2.1 milestone May 23, 2021
@keilw
Copy link
Member

keilw commented Jun 7, 2021

@fawidmer Please check out the 2.1 version of uom-lib-jackson just released last night.

@fawidmer
Copy link
Author

fawidmer commented Jun 9, 2021

@keilw: Seems to be working perfectly now, thanks a lot for your help!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants