use of javax.json.bind.annotation.JsonbNumberFormat in project smallrye-graphql by smallrye.
the class JsonStringReader method formattedNumber.
private Number formattedNumber(String input) {
String locale = null;
String format = null;
JsonbNumberFormat jsonbNumberFormat = field.getAnnotation(JsonbNumberFormat.class);
if (jsonbNumberFormat != null) {
locale = jsonbNumberFormat.locale();
format = jsonbNumberFormat.value();
}
NumberFormat numberFormat = field.getAnnotation(NumberFormat.class);
if (numberFormat != null) {
locale = numberFormat.locale();
format = numberFormat.value();
}
java.text.NumberFormat nf;
if (format != null && !format.isEmpty()) {
nf = new DecimalFormat(format);
} else if (locale != null && !locale.isEmpty()) {
nf = java.text.NumberFormat.getInstance(Locale.forLanguageTag(locale));
} else {
nf = new DecimalFormat();
}
try {
return nf.parse(input);
} catch (ParseException e) {
throw new InvalidResponseException("Can't parse number", e);
}
}
Aggregations