All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adgear.anoa.read.FloatReader Maven / Gradle / Ivy

Go to download

Core classes for Anoa library, which aims to be a safe, convenient and fast record de/serialization wrapper for the Avro, Thrift and Jackson libraries, using the functional idioms of Java 8. The anoa-core module tries to keep upstream dependencies to a minimum.

There is a newer version: 3.1.2
Show newest version
package com.adgear.anoa.read;

import com.adgear.anoa.AnoaJacksonTypeException;
import com.fasterxml.jackson.core.JsonParser;

import java.io.IOException;

class FloatReader extends AbstractReader {

  @Override
  protected Float read(JsonParser jacksonParser) throws IOException {
    return (float) jacksonParser.getValueAsDouble();
  }

  @Override
  protected Float readStrict(JsonParser jacksonParser) throws AnoaJacksonTypeException, IOException {
    switch (jacksonParser.getCurrentToken()) {
      case VALUE_NUMBER_FLOAT:
        return jacksonParser.getFloatValue();
      case VALUE_NUMBER_INT:
        try {
          return (float) jacksonParser.getValueAsDouble();
        } catch (NumberFormatException e) {
          throw new AnoaJacksonTypeException(e);
        }
      case VALUE_NULL:
        return null;
      default:
        throw new AnoaJacksonTypeException("Token is not number: " + jacksonParser.getCurrentToken());
    }  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy