Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3-SNAPSHOT
2.3.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ dependencies {
compile 'com.squareup.okhttp:okhttp:2.7.5'
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
compile 'com.google.code.gson:gson:2.8.1'
compile 'joda-time:joda-time:2.9.9'
compile 'org.threeten:threetenbp:1.3.5'
testCompile 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lazy val root = (project in file(".")).
"com.squareup.okhttp" % "okhttp" % "2.7.5",
"com.squareup.okhttp" % "logging-interceptor" % "2.7.5",
"com.google.code.gson" % "gson" % "2.8.1",
"joda-time" % "joda-time" % "2.9.9" % "compile",
"org.threeten" % "threetenbp" % "1.3.5" % "compile",
"junit" % "junit" % "4.12" % "test",
"com.novocode" % "junit-interface" % "0.10" % "test"
)
Expand Down
Empty file modified samples/client/petstore-security-test/java/okhttp-gson/gradlew
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@
<version>${gson-version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${jodatime-version}</version>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>${threetenbp-version}</version>
</dependency>
<!-- test dependencies -->
<dependency>
Expand All @@ -209,7 +209,7 @@
<swagger-core-version>1.5.15</swagger-core-version>
<okhttp-version>2.7.5</okhttp-version>
<gson-version>2.8.1</gson-version>
<jodatime-version>2.9.9</jodatime-version>
<threetenbp-version>1.3.5</threetenbp-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.12</junit-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.squareup.okhttp.logging.HttpLoggingInterceptor.Level;
import okio.BufferedSink;
import okio.Okio;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormatter;
import org.threeten.bp.LocalDate;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.format.DateTimeFormatter;

import javax.net.ssl.*;
import java.io.File;
Expand Down Expand Up @@ -231,8 +231,8 @@ public ApiClient setSqlDateFormat(DateFormat dateFormat) {
return this;
}

public ApiClient setDateTimeFormat(DateTimeFormatter dateFormat) {
this.json.setDateTimeFormat(dateFormat);
public ApiClient setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
this.json.setOffsetDateTimeFormat(dateFormat);
return this;
}

Expand Down Expand Up @@ -446,7 +446,7 @@ public ApiClient setConnectTimeout(int connectionTimeout) {
public String parameterToString(Object param) {
if (param == null) {
return "";
} else if (param instanceof Date || param instanceof DateTime || param instanceof LocalDate) {
} else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) {
//Serialize to json string and remove the " enclosing characters
String jsonStr = json.serialize(param);
return jsonStr.substring(1, jsonStr.length() - 1);
Expand Down Expand Up @@ -551,12 +551,13 @@ public String sanitizeFilename(String filename) {
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* "* / *" is also default to JSON
* @param mime MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public boolean isJsonMime(String mime) {
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json"));
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
}

/**
Expand Down Expand Up @@ -587,11 +588,11 @@ public String selectHeaderAccept(String[] accepts) {
*
* @param contentTypes The Content-Type array to select from
* @return The Content-Type header to use. If the given array is empty,
* JSON will be used.
* or matches "any", JSON will be used.
*/
public String selectHeaderContentType(String[] contentTypes) {
if (contentTypes.length == 0) {
return "application/json";
if (contentTypes.length == 0 || contentTypes[0].equals("*/*")) {
return "application/json";
}
for (String contentType : contentTypes) {
if (isJsonMime(contentType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
import com.google.gson.internal.bind.util.ISO8601Utils;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import org.threeten.bp.LocalDate;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.format.DateTimeFormatter;

import java.io.IOException;
import java.io.StringReader;
Expand All @@ -38,14 +37,14 @@ public class JSON {
private boolean isLenientOnJson = false;
private DateTypeAdapter dateTypeAdapter = new DateTypeAdapter();
private SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter();
private DateTimeTypeAdapter dateTimeTypeAdapter = new DateTimeTypeAdapter();
private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter();
private LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter();

public JSON() {
gson = new GsonBuilder()
.registerTypeAdapter(Date.class, dateTypeAdapter)
.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
.registerTypeAdapter(DateTime.class, dateTimeTypeAdapter)
.registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter)
.registerTypeAdapter(LocalDate.class, localDateTypeAdapter)
.create();
}
Expand Down Expand Up @@ -114,18 +113,17 @@ public <T> T deserialize(String body, Type returnType) {
}

/**
* Gson TypeAdapter for Joda DateTime type
* Gson TypeAdapter for JSR310 OffsetDateTime type
*/
public static class DateTimeTypeAdapter extends TypeAdapter<DateTime> {
public static class OffsetDateTimeTypeAdapter extends TypeAdapter<OffsetDateTime> {

private final DateTimeFormatter parseFormatter = ISODateTimeFormat.dateOptionalTimeParser();
private final DateTimeFormatter printFormatter = ISODateTimeFormat.dateTime();
private DateTimeFormatter formatter;

public DateTimeTypeAdapter() {
this(ISODateTimeFormat.dateTime().withOffsetParsed());
public OffsetDateTimeTypeAdapter() {
this(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}

public DateTimeTypeAdapter(DateTimeFormatter formatter) {
public OffsetDateTimeTypeAdapter(DateTimeFormatter formatter) {
this.formatter = formatter;
}

Expand All @@ -134,36 +132,39 @@ public void setFormat(DateTimeFormatter dateFormat) {
}

@Override
public void write(JsonWriter out, DateTime date) throws IOException {
public void write(JsonWriter out, OffsetDateTime date) throws IOException {
if (date == null) {
out.nullValue();
} else {
out.value(printFormatter.print(date));
out.value(formatter.format(date));
}
}

@Override
public DateTime read(JsonReader in) throws IOException {
public OffsetDateTime read(JsonReader in) throws IOException {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
return parseFormatter.parseDateTime(date);
if (date.endsWith("+0000")) {
date = date.substring(0, date.length()-5) + "Z";
}
return OffsetDateTime.parse(date, formatter);
}
}
}

/**
* Gson TypeAdapter for Joda LocalDate type
* Gson TypeAdapter for JSR310 LocalDate type
*/
public class LocalDateTypeAdapter extends TypeAdapter<LocalDate> {

private DateTimeFormatter formatter;

public LocalDateTypeAdapter() {
this(ISODateTimeFormat.date());
this(DateTimeFormatter.ISO_LOCAL_DATE);
}

public LocalDateTypeAdapter(DateTimeFormatter formatter) {
Expand All @@ -179,7 +180,7 @@ public void write(JsonWriter out, LocalDate date) throws IOException {
if (date == null) {
out.nullValue();
} else {
out.value(formatter.print(date));
out.value(formatter.format(date));
}
}

Expand All @@ -191,13 +192,13 @@ public LocalDate read(JsonReader in) throws IOException {
return null;
default:
String date = in.nextString();
return formatter.parseLocalDate(date);
return LocalDate.parse(date, formatter);
}
}
}

public JSON setDateTimeFormat(DateTimeFormatter dateFormat) {
dateTimeTypeAdapter.setFormat(dateFormat);
public JSON setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
offsetDateTimeTypeAdapter.setFormat(dateFormat);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

2 changes: 1 addition & 1 deletion samples/client/petstore/java/jersey1/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/jersey2/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/okhttp-gson/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/resteasy/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/resttemplate/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/retrofit2/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/retrofit2rx/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/retrofit2rx2/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ This endpoint does not need any parameter.

### Return type

[**Map&lt;String, Integer&gt;**](Map.md)
**Map&lt;String, Integer&gt;**

### Authorization

Expand Down