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

com.vladkrava.converter.AvroToJsonConverter Maven / Gradle / Ivy

Go to download

Enables conversion of Apache Avro object into popular data formats: JSON, XML, etc

There is a newer version: 1.0.1
Show newest version
package com.vladkrava.converter;

import org.apache.avro.specific.SpecificRecord;

import com.vladkrava.converter.serialization.AvroSerializer;
import com.vladkrava.converter.serialization.DataSerializationException;

/**
 * Converting data from Avro's SpecificRecord object to JSON string
 *
 * @author Vlad Krava - [email protected]
 * @see SpecificRecord
 * @see SourceConverter
 * @see AvroSerializer
 * @since 0.1-SNAPSHOT
 */
public class AvroToJsonConverter extends AvroSerializer implements SourceConverter {

    /**
     * Performs converting to JSON string
     *
     * @param source - Avro's source object
     * @return JSON {@link String} on successful data serialization or null if Avro's source object is null
     * @throws DataSerializationException - on any exception with serialization from source datatype to a byte array
     */
    @Override
    public String convert(final T source) throws DataSerializationException {
        final byte[] json = serialize(source);
        return json == null ? null : new String(json);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy