Skip to content

Commit

Permalink
DSL-JSON v2.0.2
Browse files Browse the repository at this point in the history
Bugfix for List analysis with annotations.
Fixing binder validation.
  • Loading branch information
zapov committed Aug 29, 2023
1 parent f560001 commit 15d66f0
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 22 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ To use annotation processor it is sufficient to just reference the library:
<dependency>
<groupId>com.dslplatform</groupId>
<artifactId>dsl-json</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
</dependency>

For use in Android, Gradle can be configured with:
Expand All @@ -79,8 +79,8 @@ For use in Android, Gradle can be configured with:
}
}
dependencies {
compile 'com.dslplatform:dsl-json:2.0.1'
annotationProcessor 'com.dslplatform:dsl-json:2.0.1'
compile 'com.dslplatform:dsl-json:2.0.2'
annotationProcessor 'com.dslplatform:dsl-json:2.0.2'
provided 'javax.json.bind:javax.json.bind-api:1.0'
}

Expand Down Expand Up @@ -319,7 +319,7 @@ To avoid some Java/Scala conversion issues it's best to use Scala specific API v

For SBT dependency can be added as:

libraryDependencies += "com.dslplatform" %% "dsl-json-scala" % "2.0.1"
libraryDependencies += "com.dslplatform" %% "dsl-json-scala" % "2.0.2"

### Kotlin support

Expand All @@ -330,8 +330,8 @@ When used with Gradle, configuration can be done via:
kotlin("kapt") version "1.8.0"
}
dependencies {
implementation("com.dslplatform:dsl-json:2.0.1")
kapt("com.dslplatform:dsl-json:2.0.1")
implementation("com.dslplatform:dsl-json:2.0.2")
kapt("com.dslplatform:dsl-json:2.0.2")
}

## FAQ
Expand Down
2 changes: 1 addition & 1 deletion examples/ArrayFormat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.dslplatform</groupId>
<artifactId>array-format-example</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<dependencies>
<dependency>
<groupId>com.dslplatform</groupId>
Expand Down
2 changes: 1 addition & 1 deletion examples/AutoValue/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.dslplatform</groupId>
<artifactId>autovalue-example</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<dependencies>
<dependency>
<groupId>com.dslplatform</groupId>
Expand Down
2 changes: 1 addition & 1 deletion examples/Jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.dslplatform</groupId>
<artifactId>jackson-example</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<dependencies>
<dependency>
<groupId>com.dslplatform</groupId>
Expand Down
2 changes: 1 addition & 1 deletion examples/Jsonb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.dslplatform</groupId>
<artifactId>jsonb-example</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<dependencies>
<dependency>
<groupId>com.dslplatform</groupId>
Expand Down
6 changes: 3 additions & 3 deletions examples/Kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ plugins {
}

group = "kotlin-dsl-json"
version = "2.0.1-SNAPSHOT"
version = "2.0.2-SNAPSHOT"

repositories {
mavenCentral()
mavenLocal()
}

dependencies {
implementation("com.dslplatform:dsl-json:2.0.1")
kapt("com.dslplatform:dsl-json:2.0.1")
implementation("com.dslplatform:dsl-json:2.0.2")
kapt("com.dslplatform:dsl-json:2.0.2")
}

tasks.withType<KotlinCompile>() {
Expand Down
2 changes: 1 addition & 1 deletion examples/Lombok/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.dslplatform</groupId>
<artifactId>lombok-example</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<dependencies>
<dependency>
<groupId>com.dslplatform</groupId>
Expand Down
2 changes: 1 addition & 1 deletion examples/MavenJava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.dslplatform</groupId>
<artifactId>maven-java-example</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<dependencies>
<dependency>
<groupId>com.dslplatform</groupId>
Expand Down
2 changes: 1 addition & 1 deletion examples/Polymorphism/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.dslplatform</groupId>
<artifactId>polymorphic-example</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<dependencies>
<dependency>
<groupId>com.dslplatform</groupId>
Expand Down
2 changes: 1 addition & 1 deletion examples/Reflection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.dslplatform</groupId>
<artifactId>reflection-example</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<dependencies>
<dependency>
<groupId>com.dslplatform</groupId>
Expand Down
4 changes: 2 additions & 2 deletions examples/Scala/build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name := "DSL-JSON Scala example"
version := "2.0.1"
version := "2.0.2"
organization := "com.dslplatform.json.example"
scalaVersion := "2.13.11"

ThisBuild / useCoursier := false
resolvers += Resolver.mavenLocal

libraryDependencies += "com.dslplatform" %% "dsl-json-scala" % "2.0.1"
libraryDependencies += "com.dslplatform" %% "dsl-json-scala" % "2.0.2"
libraryDependencies += "javax.json.bind" % "javax.json.bind-api" % "1.0"
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.dslplatform</groupId>
<artifactId>json-examples</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<packaging>pom</packaging>
<url>https://github.com/ngs-doo/dsl-json</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,9 @@ private ConverterInfo validateConverter(TypeElement converter, TypeMirror type)
"Specified converter: '" + converter.getQualifiedName() + "' has invalid type for write method. It must be of type: 'void write(com.dslplatform.json.JsonWriter, " + javaType + ")'. " + additionalDescription,
converter,
getAnnotation(converter, converterType));
} else if (legacyDeclaration && jsonBinderField != null && !("com.dslplatform.json.JsonReader.BindObject<" + fullName + ">").equals(jsonBinderField.asType().toString())
|| jsonBinderMethod != null && !("com.dslplatform.json.JsonReader.BindObject<" + fullName + ">").equals(jsonBinderMethod.getReturnType().toString())) {
} else if (legacyDeclaration &&
(jsonBinderField != null && !("com.dslplatform.json.JsonReader.BindObject<" + fullName + ">").equals(jsonBinderField.asType().toString())
|| jsonBinderMethod != null && !("com.dslplatform.json.JsonReader.BindObject<" + fullName + ">").equals(jsonBinderMethod.getReturnType().toString())) ) {
hasError = true;
messager.printMessage(
Diagnostic.Kind.ERROR,
Expand Down
15 changes: 15 additions & 0 deletions tests-java8/src/test/java/com/dslplatform/json/BinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,19 @@ public void readWorks() throws IOException {
Assert.assertEquals("abc", wc.a);
Assert.assertEquals("value", wc.b.value);
}

@Test
public void nestedBindWorks() throws IOException {
byte[] input = "{\"firstname\":\"me\", \"surname\":\"for-real\",\"age\":42}".getBytes(StandardCharsets.UTF_8);
MutablePerson wc = dslJson.deserialize(MutablePerson.class, input, input.length);
Assert.assertEquals("me", wc.firstname.value());
Assert.assertEquals("for-real", wc.surname.value());
Assert.assertEquals(42, wc.age);
JsonWriter writer = dslJson.newWriter();
dslJson.serialize(writer, wc);
String output = writer.toString();
Assert.assertTrue(output.contains("\"firstname\":\"me\""));
Assert.assertTrue(output.contains("\"surname\":\"for-real\""));
Assert.assertTrue(output.contains("\"age\":42"));
}
}
39 changes: 39 additions & 0 deletions tests-java8/src/test/java/com/dslplatform/json/MutablePerson.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.dslplatform.json;

import java.io.IOException;

@CompiledJson
public class MutablePerson {

public static class Name {
private String value;
public String value() { return value; }
public static Name create(String value) {
Name fn = new Name();
fn.value = value;
return fn;
}

//When creating wrapper classes, we can "abuse" them and make them "locally mutable"
//so when deserializing instance we can just change the values instead of allocate even more objects
@JsonConverter(target = Name.class)
public static class NameConverter {
public static void write(JsonWriter writer, Name instance) {
writer.writeString(instance.value);
}
public static Name read(JsonReader reader) throws IOException {
return Name.create(reader.readString());
}

public static Name bind(JsonReader reader, Name instance) throws IOException {
if (instance == null) instance = new Name();
instance.value = reader.readString();
return instance;
}
}
}

public Name firstname;
public Name surname;
public int age;
}

0 comments on commit 15d66f0

Please sign in to comment.