Skip to content

Commit 105ba44

Browse files
committed
Initial wip
1 parent 0bd7175 commit 105ba44

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3734
-0
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
indent_size = 2
9+
indent_style = space
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
spaces_around_operators = true

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
target/
2+
build/
3+
.idea/
4+
*.iml
5+
.gradle

blackbox-test/pom.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.avaje.mason</groupId>
6+
<artifactId>mason-parent</artifactId>
7+
<version>0.1-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>blackbox-test</artifactId>
11+
<name>blackbox test</name>
12+
<description>test module</description>
13+
14+
<dependencies>
15+
16+
<dependency>
17+
<groupId>org.avaje.mason</groupId>
18+
<artifactId>mason-core</artifactId>
19+
<version>0.1-SNAPSHOT</version>
20+
</dependency>
21+
22+
<!-- test dependencies -->
23+
<dependency>
24+
<groupId>io.avaje</groupId>
25+
<artifactId>junit</artifactId>
26+
<version>1.0</version>
27+
<scope>test</scope>
28+
</dependency>
29+
30+
</dependencies>
31+
32+
33+
<build>
34+
<plugins>
35+
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-compiler-plugin</artifactId>
39+
<version>3.8.1</version>
40+
<configuration>
41+
<source>1.8</source>
42+
<target>1.8</target>
43+
<!-- Turn off annotation processing for building -->
44+
<compilerArgument>-proc:none</compilerArgument>
45+
</configuration>
46+
</plugin>
47+
48+
<plugin>
49+
<groupId>org.moditect</groupId>
50+
<artifactId>moditect-maven-plugin</artifactId>
51+
<version>1.0.0.RC1</version>
52+
<executions>
53+
<execution>
54+
<id>add-module-infos</id>
55+
<phase>package</phase>
56+
<goals>
57+
<goal>add-module-info</goal>
58+
</goals>
59+
<configuration>
60+
<module>
61+
<moduleInfoFile>src/main/java9/module-info.java</moduleInfoFile>
62+
</module>
63+
</configuration>
64+
</execution>
65+
</executions>
66+
</plugin>
67+
68+
</plugins>
69+
</build>
70+
71+
</project>

mason-core/pom.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.avaje.mason</groupId>
8+
<artifactId>mason-core</artifactId>
9+
<version>0.1-SNAPSHOT</version>
10+
11+
<parent>
12+
<groupId>org.avaje.mason</groupId>
13+
<artifactId>mason-parent</artifactId>
14+
<version>0.1-SNAPSHOT</version>
15+
</parent>
16+
17+
<properties>
18+
<maven.compiler.source>11</maven.compiler.source>
19+
<maven.compiler.target>11</maven.compiler.target>
20+
</properties>
21+
22+
<dependencies>
23+
24+
<dependency>
25+
<groupId>com.fasterxml.jackson.core</groupId>
26+
<artifactId>jackson-core</artifactId>
27+
<version>2.12.5</version>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>io.avaje</groupId>
32+
<artifactId>junit</artifactId>
33+
<version>1.0</version>
34+
<scope>test</scope>
35+
</dependency>
36+
37+
</dependencies>
38+
39+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.avaje.mason;
2+
3+
import java.io.IOException;
4+
import java.lang.annotation.Annotation;
5+
import java.lang.reflect.Type;
6+
import java.util.Set;
7+
import java.util.function.Supplier;
8+
9+
public abstract class JsonAdapter<T> {
10+
11+
public void toJsonFrom(JsonWriter writer, Supplier<T> supplier) throws IOException {
12+
toJson(writer, supplier.get());
13+
}
14+
15+
public abstract void toJson(JsonWriter writer, T value) throws IOException;
16+
17+
public abstract T fromJson(JsonReader reader) throws IOException;
18+
19+
/**
20+
* Return a null safe version of this adapter.
21+
*/
22+
public final JsonAdapter<T> nullSafe() {
23+
if (this instanceof NullSafeJsonAdapter) {
24+
return this;
25+
}
26+
return new NullSafeJsonAdapter<>(this);
27+
}
28+
29+
public interface Factory {
30+
31+
JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Jsonb jsonb);
32+
}
33+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2018 Square, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.avaje.mason;
17+
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.Retention;
21+
22+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
23+
24+
/**
25+
* Customizes how a type is encoded as JSON.
26+
*/
27+
@Retention(RUNTIME)
28+
@Documented
29+
public @interface JsonClass {
30+
31+
/**
32+
* True to trigger the annotation processor to generate an adapter for this type.
33+
*
34+
* <p>There are currently some restrictions on which types that can be used with generated
35+
* adapters:
36+
*
37+
* <ul>
38+
* <li>The class must be implemented in Kotlin (unless using a custom generator, see {@link
39+
* #generator()}).
40+
* <li>The class may not be an abstract class, an inner class, or a local class.
41+
* <li>All superclasses must be implemented in Kotlin.
42+
* <li>All properties must be public, protected, or internal.
43+
* <li>All properties must be either non-transient or have a default value.
44+
* </ul>
45+
*/
46+
boolean generateAdapter();
47+
48+
/**
49+
* Not used yet.
50+
*/
51+
String generator() default "";
52+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2015 Square, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.avaje.mason;
17+
18+
/**
19+
* Thrown when the data in a JSON document doesn't match the data expected by the caller. For
20+
* example, suppose the application expects a boolean but the JSON document contains a string. When
21+
* the call to {@link JsonReader#nextBoolean} is made, a {@code JsonDataException} is thrown.
22+
*
23+
* <p>Exceptions of this type should be fixed by either changing the application code to accept the
24+
* unexpected JSON, or by changing the JSON to conform to the application's expectations.
25+
*
26+
* <p>This exception may also be triggered if a document's nesting exceeds 31 levels. This depth is
27+
* sufficient for all practical applications, but shallow enough to avoid uglier failures like
28+
* {@link StackOverflowError}.
29+
*/
30+
public final class JsonDataException extends RuntimeException {
31+
public JsonDataException() {
32+
}
33+
34+
public JsonDataException(String message) {
35+
super(message);
36+
}
37+
38+
public JsonDataException(Throwable cause) {
39+
super(cause);
40+
}
41+
42+
public JsonDataException(String message, Throwable cause) {
43+
super(message, cause);
44+
}
45+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2016 Square, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.avaje.mason;
17+
18+
import java.io.IOException;
19+
20+
/**
21+
* Thrown when the data being parsed is not encoded as valid JSON.
22+
*/
23+
public final class JsonEncodingException extends IOException {
24+
public JsonEncodingException(String message) {
25+
super(message);
26+
}
27+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2015 Square, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.avaje.mason;
17+
18+
import java.lang.annotation.Documented;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.Target;
21+
22+
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
23+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
24+
25+
/**
26+
* Annotates another annotation, causing it to specialize how values are encoded and decoded.
27+
*/
28+
@Target(ANNOTATION_TYPE)
29+
@Retention(RUNTIME)
30+
@Documented
31+
public @interface JsonQualifier {
32+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.avaje.mason;
2+
3+
import java.io.IOException;
4+
5+
public interface JsonReader {
6+
7+
void beginArray();
8+
9+
void endArray();
10+
11+
boolean hasNextElement() throws IOException;
12+
13+
void beginObject() throws IOException;
14+
15+
void endObject() throws IOException;
16+
17+
boolean hasNextField() throws IOException;
18+
19+
String nextField() throws IOException;
20+
21+
boolean nextBoolean() throws IOException;
22+
23+
int nextInt() throws IOException;
24+
25+
long nextLong() throws IOException;
26+
27+
String nextString() throws IOException;
28+
29+
boolean peekIsNull();
30+
31+
<T> T nextNull();
32+
33+
String path();
34+
35+
void promoteNameToValue();
36+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.avaje.mason;
2+
3+
import java.io.*;
4+
import java.util.List;
5+
6+
public interface JsonType<T> {
7+
8+
JsonType<List<T>> list();
9+
10+
String toJson(T bean) throws IOException;
11+
12+
void toJson(JsonWriter writer, T bean) throws IOException;
13+
14+
void toJson(Writer writer, T bean) throws IOException;
15+
16+
void toJson(OutputStream outputStream, T bean) throws IOException;
17+
18+
T fromJson(JsonReader reader) throws IOException;
19+
20+
T fromJson(String content) throws IOException;
21+
22+
T fromJson(Reader reader) throws IOException;
23+
24+
T fromJson(InputStream inputStream) throws IOException;
25+
26+
}

0 commit comments

Comments
 (0)