-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from upb-uc4/feature/instant
Feature/instant
- Loading branch information
Showing
18 changed files
with
292 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
UC4-chaincode/src/main/java/de/upb/cs/uc4/chaincode/helper/DateSerializer.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
UC4-chaincode/src/main/java/de/upb/cs/uc4/chaincode/helper/InstantAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package de.upb.cs.uc4.chaincode.helper; | ||
|
||
import java.lang.reflect.Type; | ||
import java.time.Instant; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import java.util.TimeZone; | ||
|
||
import com.google.gson.*; | ||
|
||
public class InstantAdapter implements JsonDeserializer<Instant>, JsonSerializer<Instant> { | ||
|
||
private static final TimeZone tz = TimeZone.getTimeZone("UTC"); | ||
|
||
@Override | ||
public Instant deserialize(JsonElement element, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { | ||
String dateString = element.getAsString(); | ||
return internalDeserialize(dateString); | ||
} | ||
|
||
@Override | ||
public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { | ||
return new JsonPrimitive(internalSerialize(src)); | ||
} | ||
|
||
public static String internalSerialize(Instant src){ | ||
return DateTimeFormatter.ISO_INSTANT.format(src); | ||
} | ||
|
||
public static Instant internalDeserialize(String src) { | ||
try { | ||
return Instant.from(DateTimeFormatter.ISO_ZONED_DATE_TIME.parse(src)); | ||
} catch (DateTimeParseException e) { | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.