v0.2.0
- Introduced a JSON library. It is immutable at its core and very fast, beating GSON and Jackson in performance benchmarks.
- Added JSON codecs and
Codec.builder(the equivalent of aBinaryTemplate) for encoding structs/records. It is fully type safe: if any part of your codec is wrong, the code will not compile. - Fixed binary array codecs always returning
Object[]. (breaking change) - Moved the
Either<L, R>codec fromalpinetoalpine.binary. (breaking change) - Removed the
BufferedImagecodec. (breaking change) - Java 25 is now required. (breaking change)
Examples
public record User(String name, int age, List<String> friends) {
public static final Codec<User> CODEC = Codec.<User>builder()
.with("name", Codec.STRING, User::name)
.with("age", Codec.INTEGER, User::age)
.with("friends", Codec.STRING.list(), User::friends)
.build(User::new);
}@Test
void testObjectCodec() {
var user = new User("Steve", 67, List.of("Alex"));
var element = object().set("name", "Steve").set("age", 67).set("friends", array("Alex"));
assertEquals(element, User.CODEC.encode(Transcoder.JSON, user));
assertEquals(user, User.CODEC.decode(Transcoder.JSON, element));
}Benchmarks
Benchmark Mode Cnt Score Error Units
JsonReadBenchmark.alpine avgt 5 937.234 ± 200.563 ns/op
JsonReadBenchmark.fastjson avgt 5 806.342 ± 37.452 ns/op
JsonReadBenchmark.gson avgt 5 1719.493 ± 70.058 ns/op
JsonReadBenchmark.jackson avgt 5 1376.538 ± 42.703 ns/op
JsonWriteBenchmark.alpine avgt 5 977.201 ± 79.462 ns/op
JsonWriteBenchmark.fastjson avgt 5 341.163 ± 45.274 ns/op
JsonWriteBenchmark.gson avgt 5 1582.001 ± 20.430 ns/op
JsonWriteBenchmark.jackson avgt 5 591.187 ± 10.237 ns/op
To try the benchmarks yourself, run ./gradlew jmh.
Installation
Binary
Gradle (Kotlin)
dependencies {
implementation("dev.mudkip:alpine-binary:0.2.0")
implementation("io.netty:netty-buffer:4.2.10.Final")
}Gradle (Groovy)
dependencies {
implementation 'dev.mudkip:alpine-binary:0.2.0'
implementation 'io.netty:netty-buffer:4.2.10.Final'
}Maven
<dependency>
<groupId>dev.mudkip</groupId>
<artifactId>alpine-binary</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
<version>4.2.10.Final</version>
</dependency>JSON
Gradle (Kotlin)
dependencies {
implementation("dev.mudkip:alpine-json:0.2.0")
}Gradle (Groovy)
dependencies {
implementation 'dev.mudkip:alpine-json:0.2.0'
}Maven
<dependency>
<groupId>dev.mudkip</groupId>
<artifactId>alpine-json</artifactId>
<version>0.2.0</version>
</dependency>