
global.namespace.truelicense.v2.json.JsonCodec Maven / Gradle / Ivy
/*
* Copyright (C) 2005-2017 Schlichtherle IT Services.
* All rights reserved. Use is subject to license terms.
*/
package global.namespace.truelicense.v2.json;
import com.fasterxml.jackson.databind.ObjectMapper;
import global.namespace.fun.io.api.Decoder;
import global.namespace.fun.io.api.Encoder;
import global.namespace.fun.io.api.Socket;
import global.namespace.truelicense.api.codec.Codec;
import global.namespace.truelicense.obfuscate.Obfuscate;
import java.io.InputStream;
import java.io.OutputStream;
import static global.namespace.fun.io.jackson.Jackson.json;
/**
* A codec which encodes/decodes objects to/from JSON with an
* {@link ObjectMapper}.
* This type of codec is used for V2/JSON format license keys.
* This class is immutable.
*
* @author Christian Schlichtherle
*/
final class JsonCodec implements Codec {
@Obfuscate
private static final String CONTENT_TYPE = "application/json";
@Obfuscate
private static final String CONTENT_TRANSFER_ENCODING = "8bit";
private final global.namespace.fun.io.api.Codec codec;
/**
* Constructs a new JSON codec.
*
* @param mapper the object mapper.
*/
JsonCodec(final ObjectMapper mapper) { this.codec = json(mapper); }
/**
* {@inheritDoc}
*
* The implementation in the class {@link JsonCodec}
* returns {@code "application/json"}.
*
* @see RFC 4627
*/
@Override
public String contentType() { return CONTENT_TYPE; }
/**
* {@inheritDoc}
*
* The implementation in the class {@link JsonCodec}
* returns {@code "8bit"}.
*
* @see RFC 4627
*/
@Override
public String contentTransferEncoding() { return CONTENT_TRANSFER_ENCODING; }
@Override
public Encoder encoder(Socket output) { return codec.encoder(output); }
@Override
public Decoder decoder(Socket input) { return codec.decoder(input); }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy