
com.synerset.unitility.spring.serialization.PhysicalQuantityWebMvcConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unitility-spring Show documentation
Show all versions of unitility-spring Show documentation
The Java Physics Units of Measure Library - Unitility, Spring extension.
This module integrates unitility-core and unitility-jackson. It provides a preconfigured Jackson module
and WebMvcConfigurer for automatic serialization/deserialization of all supported physical quantity types.
This configuration is automatically included through Spring's autoconfiguration.
package com.synerset.unitility.spring.serialization;
import com.synerset.unitility.unitsystem.PhysicalQuantity;
import com.synerset.unitility.unitsystem.Unit;
import com.synerset.unitility.unitsystem.util.PhysicalQuantityParsingFactory;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
/**
* The PhysicalQuantityWebMvcConverter class is a Spring converter for converting strings to PhysicalQuantity instances.
*
* @param The type of unit associated with the PhysicalQuantity.
* @param The type of PhysicalQuantity.
*/
public class PhysicalQuantityWebMvcConverter> implements Converter {
private final Class targetClass;
private final PhysicalQuantityParsingFactory parsingFactory;
public PhysicalQuantityWebMvcConverter(Class targetClass, PhysicalQuantityParsingFactory parsingFactory) {
this.targetClass = targetClass;
this.parsingFactory = parsingFactory;
}
/**
* Converts a string to a PhysicalQuantity instance using the {@link PhysicalQuantityParsingFactory}.
* Spring calls this method to convert a string input to a PhysicalQuantity instance using the
* {@link PhysicalQuantityParsingFactory}.
*
* @param source The string representation of the PhysicalQuantity.
* @return A PhysicalQuantity instance.
*/
@Override
public Q convert(@NonNull String source) {
return parsingFactory.parse(targetClass, source);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy