argoproj / argoproj/argo-workflows
v3.3.9 still has serialization problems
- Dominant language
- Go
- Stars
- 17k
- Forks
- 3.7k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 138
Description
After I used v3.3.9, I found that there was still a serialization problem. It was not the original DateTime problem but the java.time.Instant problem. I created a new package` io.argoproj.workflow` in my project, which added `JSON.java`, then copy `io.argoproj.workflow.JSON` in the sdk source code and modify it in my `JSON.java`, and modify the JSON constructor as follows:
```java
public class JSON {
//add
private InstantTypeAdapter instantTypeAdapter = new InstantTypeAdapter();
//edit
public JSON() {
gson = createGson()
.registerTypeAdapter(Date.class, dateTypeAdapter)
.registerTypeAdapter(Instant.class, instantTypeAdapter)
.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
.registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter)
.registerTypeAdapter(LocalDate.class, localDateTypeAdapter)
.registerTypeAdapter(byte[].class, byteArrayAdapter)
.create();
}
//add
public static class InstantTypeAdapter extends TypeAdapter {
private Instant dateFormat;
public InstantTypeAdapter() {
}
public InstantTypeAdapter(Instant instant) {
this.dateFormat = dateFormat;
}
public void setFormat(Instant instant) {
this.dateFormat = dateFormat;
}
@Override
public void write(JsonWriter out, Instant date) throws IOException {
if (date == null) {
out.nullValue();
} else {
out.value(FORMATTER.format(date));
}
}
@Override
public Instant read(JsonReader in) throws IOException {
try {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
if (date == null) {
return null;
}
return FORMATTER.parse(date, Instant::from);
}
} catch (IllegalArgumentException e) {
throw new JsonParseException(e);
}
}
}
}
}
```
_Originally posted by @sanqiuli in https://github.com/argoproj/argo-workflows/issues/9148#issuecomment-1250563985_
Creating a new issue for more visibility
Contributor guide
Research direction
Locate JSON.java in the SDK source and inspect how the v3.3.9 client handles java.time.Instant alongside the existing date adapters. Reproduce the reported Instant serialization problem and compare serialization and deserialization behavior; done means Instant values work without the reported error.
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
- 35/100