-
Notifications
You must be signed in to change notification settings - Fork 43
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 #712 from goldmansachs/serialization
Serialization
- Loading branch information
Showing
20 changed files
with
653 additions
and
127 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
48 changes: 48 additions & 0 deletions
48
dmn-runtime/src/main/java/com/gs/dmn/runtime/serialization/LocalDateDeserializer.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,48 @@ | ||
/* | ||
* Copyright 2016 Goldman Sachs. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package com.gs.dmn.runtime.serialization; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.ObjectCodec; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.gs.dmn.feel.lib.type.time.pure.TemporalDateTimeLib; | ||
import com.gs.dmn.runtime.DMNRuntimeException; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDate; | ||
|
||
public class LocalDateDeserializer extends JsonDeserializer<LocalDate> { | ||
private final TemporalDateTimeLib dateTimeLib = new TemporalDateTimeLib(); | ||
|
||
public LocalDateDeserializer() { | ||
} | ||
|
||
@Override | ||
public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { | ||
ObjectCodec oc = jp.getCodec(); | ||
JsonNode node = oc.readTree(jp); | ||
|
||
try { | ||
String literal = node.asText(); | ||
if (literal == null) { | ||
return null; | ||
} else { | ||
return dateTimeLib.date(literal); | ||
} | ||
} catch (Exception e) { | ||
throw new DMNRuntimeException(String.format("Error deserializing '%s' ", node), e); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
dmn-runtime/src/main/java/com/gs/dmn/runtime/serialization/LocalDateSerializer.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,29 @@ | ||
/* | ||
* Copyright 2016 Goldman Sachs. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package com.gs.dmn.runtime.serialization; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.gs.dmn.feel.lib.JavaTimeFEELLib; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDate; | ||
|
||
public class LocalDateSerializer extends JsonSerializer<LocalDate> { | ||
private final JavaTimeFEELLib feelLib = new JavaTimeFEELLib(); | ||
@Override | ||
public void serialize(LocalDate value, JsonGenerator gen, SerializerProvider serializers) throws IOException { | ||
gen.writeString(feelLib.string(value)); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
dmn-runtime/src/main/java/com/gs/dmn/runtime/serialization/OffsetTimeDeserializer.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,48 @@ | ||
/* | ||
* Copyright 2016 Goldman Sachs. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package com.gs.dmn.runtime.serialization; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.ObjectCodec; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.gs.dmn.feel.lib.type.time.mixed.MixedDateTimeLib; | ||
import com.gs.dmn.runtime.DMNRuntimeException; | ||
|
||
import java.io.IOException; | ||
import java.time.OffsetTime; | ||
|
||
public class OffsetTimeDeserializer extends JsonDeserializer<OffsetTime> { | ||
private final MixedDateTimeLib dateTimeLib = new MixedDateTimeLib(); | ||
|
||
public OffsetTimeDeserializer() { | ||
} | ||
|
||
@Override | ||
public OffsetTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { | ||
ObjectCodec oc = jp.getCodec(); | ||
JsonNode node = oc.readTree(jp); | ||
|
||
try { | ||
String literal = node.asText(); | ||
if (literal == null) { | ||
return null; | ||
} else { | ||
return this.dateTimeLib.time(literal); | ||
} | ||
} catch (Exception e) { | ||
throw new DMNRuntimeException(String.format("Error deserializing '%s' ", node), e); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
dmn-runtime/src/main/java/com/gs/dmn/runtime/serialization/OffsetTimeSerializer.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,29 @@ | ||
/* | ||
* Copyright 2016 Goldman Sachs. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package com.gs.dmn.runtime.serialization; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.gs.dmn.feel.lib.MixedJavaTimeFEELLib; | ||
|
||
import java.io.IOException; | ||
import java.time.OffsetTime; | ||
|
||
public class OffsetTimeSerializer extends JsonSerializer<OffsetTime> { | ||
private final MixedJavaTimeFEELLib feelLib = new MixedJavaTimeFEELLib(); | ||
@Override | ||
public void serialize(OffsetTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException { | ||
gen.writeString(feelLib.string(value)); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
dmn-runtime/src/main/java/com/gs/dmn/runtime/serialization/TemporalAccessorDeserializer.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,56 @@ | ||
/* | ||
* Copyright 2016 Goldman Sachs. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package com.gs.dmn.runtime.serialization; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.ObjectCodec; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.gs.dmn.feel.lib.type.time.pure.TemporalDateTimeLib; | ||
import com.gs.dmn.runtime.DMNRuntimeException; | ||
|
||
import java.io.IOException; | ||
import java.time.temporal.TemporalAccessor; | ||
|
||
public class TemporalAccessorDeserializer extends JsonDeserializer<TemporalAccessor> { | ||
private final TemporalDateTimeLib dateTimeLib = new TemporalDateTimeLib(); | ||
|
||
public TemporalAccessorDeserializer() { | ||
} | ||
|
||
@Override | ||
public TemporalAccessor deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { | ||
ObjectCodec oc = jp.getCodec(); | ||
JsonNode node = oc.readTree(jp); | ||
|
||
try { | ||
String literal = node.asText(); | ||
if (literal == null) { | ||
return null; | ||
} else { | ||
if (literal.contains("T")) { | ||
return dateTimeLib.dateAndTime(literal); | ||
} else { | ||
try { | ||
return this.dateTimeLib.dateTemporalAccessor(literal); | ||
} catch (Exception e) { | ||
} | ||
return this.dateTimeLib.timeTemporalAccessor(literal); | ||
} | ||
} | ||
} catch (Exception e) { | ||
throw new DMNRuntimeException(String.format("Error deserializing '%s' ", node), e); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
dmn-runtime/src/main/java/com/gs/dmn/runtime/serialization/TemporalAccessorSerializer.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,29 @@ | ||
/* | ||
* Copyright 2016 Goldman Sachs. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package com.gs.dmn.runtime.serialization; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.gs.dmn.feel.lib.JavaTimeFEELLib; | ||
|
||
import java.io.IOException; | ||
import java.time.temporal.TemporalAccessor; | ||
|
||
public class TemporalAccessorSerializer extends JsonSerializer<TemporalAccessor> { | ||
private final JavaTimeFEELLib feelLib = new JavaTimeFEELLib(); | ||
@Override | ||
public void serialize(TemporalAccessor value, JsonGenerator gen, SerializerProvider serializers) throws IOException { | ||
gen.writeString(feelLib.string(value)); | ||
} | ||
} |
Oops, something went wrong.