swagger-api / swagger-api/swagger-codegen

java.lang.IllegalArgumentException: Invalid format Exception when using org.joda.time.DateTime

Open
#9,114 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

After getting below mentioned response from the API using the swagger-codegen generated JAR file.The GSON library is generating below mentioned Exception.

API Response for reference:
[
{
"SampleTime": "2018-09-25T22:25:07.036+00:00"
},
{
"SampleTime": "2018-09-26T02:44:20+00:00"
},
{
"SampleTime": "2018-09-26T16:20:57.289+00:00"
}
]

Exception for reference:
java.lang.IllegalArgumentException: Invalid format: "2018-09-26T02:44:20+00:00" is malformed at "+00:00"
org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:945)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
com.google.gson.Gson.fromJson(Gson.java:888)
com.google.gson.Gson.fromJson(Gson.java:853)
com.google.gson.Gson.fromJson(Gson.java:802)
io.grpc.stub.ServerCalls$UnaryServerCallHandler$UnaryServerCallListener.onHalfClose(ServerCalls.java:171)
io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.halfClosed(ServerCallImpl.java:283)
io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1HalfClosed.runInContext(ServerImpl.java:707)
io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)

Swagger-codegen version

swagger-codegen-cli-2.2.1.jar

Swagger declaration file content or url
Command line used for generation

java.exe -jar swagger-codegen-cli-2.2.1.jar generate -i swagger.json -l java -o C:\Jar --import-mappings Object=java.lang.Object

Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the swagger-codegen-cli-2.2.1.jar generation command and the reported Gson parsing stack trace, using the two SampleTime values as the reproduction input. Check how the generated Java client handles these timestamps; done means both response formats can be parsed without the reported IllegalArgumentException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.