Skip to content

feature: Generic JSON Codec Abstraction (JsonCodec) #3904

@jknack

Description

@jknack

Motivation

To completely decouple Jooby applications from specific JSON engines (Jackson, Gson, Avaje, etc.), we need a generic JSON abstraction.

@FunctionalInterface
public interface JsonEncoder {
    String encode(Object value);
}

@FunctionalInterface
public interface JsonDecoder {
    // Core contract for implementors (handles complex generics)
    <T> T decode(String json, java.lang.reflect.Type type);

    // Convenience method for users
    @SuppressWarnings("unchecked")
    default <T> T decode(String json, Class<T> type) {
        return decode(json, (java.lang.reflect.Type) type);
    }
}

// The unified contract for dependency injection
public interface JsonCodec extends JsonEncoder, JsonDecoder {
}

Module Implementors:

  • jackson
  • avaje-json
  • gson
  • yasson

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions