This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
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 #54 from mkalen/feature/jsr-310
Support JSR-310 classes, pluggable ObjectMapper
- Loading branch information
Showing
10 changed files
with
208 additions
and
12 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
31 changes: 31 additions & 0 deletions
31
nodes/src/main/java/io/aexp/nodes/graphql/ObjectMapperFactory.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,31 @@ | ||
/* | ||
* Copyright (c) 2018 American Express Travel Related Services Company, Inc. | ||
* | ||
* 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 io.aexp.nodes.graphql; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public interface ObjectMapperFactory { | ||
|
||
/** | ||
* Returns a new ObjectMapper instance used for serialization. | ||
* @return ObjectMapper instance used for serialization | ||
*/ | ||
ObjectMapper newSerializerMapper(); | ||
|
||
/** | ||
* Returns a new ObjectMapper instance used for deserialization. | ||
* @return ObjectMapper instance used for deserialization | ||
*/ | ||
ObjectMapper newDeserializerMapper(); | ||
} |
49 changes: 49 additions & 0 deletions
49
nodes/src/main/java/io/aexp/nodes/graphql/internal/DefaultObjectMapperFactory.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,49 @@ | ||
/* | ||
* Copyright (c) 2018 American Express Travel Related Services Company, Inc. | ||
* | ||
* 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 io.aexp.nodes.graphql.internal; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
|
||
import io.aexp.nodes.graphql.ObjectMapperFactory; | ||
|
||
public final class DefaultObjectMapperFactory implements ObjectMapperFactory { | ||
|
||
public DefaultObjectMapperFactory() { | ||
} | ||
|
||
public ObjectMapper newSerializerMapper() { | ||
final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
// JDK8+ Time and Date handling / JSR-310 | ||
mapper.registerModule(new JavaTimeModule()); | ||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); | ||
mapper.disable(SerializationFeature.WRITE_DATES_WITH_ZONE_ID); | ||
mapper.disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS); | ||
|
||
return mapper; | ||
} | ||
|
||
public ObjectMapper newDeserializerMapper() { | ||
final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
// JDK8+ Time and Date handling / JSR-310 | ||
mapper.registerModule(new JavaTimeModule()); | ||
mapper.disable(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS); | ||
|
||
return mapper; | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
nodes/src/test/java/io/aexp/nodes/graphql/internal/DefaultObjectMapperFactoryTest.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,27 @@ | ||
/* | ||
* Copyright (c) 2018 American Express Travel Related Services Company, Inc. | ||
* | ||
* 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 io.aexp.nodes.graphql.internal; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
import org.junit.Test; | ||
|
||
public class DefaultObjectMapperFactoryTest { | ||
|
||
@Test | ||
public void defaultObjectMapperFactoryTest() { | ||
assertNotNull(new DefaultObjectMapperFactory().newSerializerMapper()); | ||
assertNotNull(new DefaultObjectMapperFactory().newDeserializerMapper()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
nodes/src/test/java/io/aexp/nodes/graphql/models/TestModelDateTime.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,33 @@ | ||
/* | ||
* Copyright (c) 2018 American Express Travel Related Services Company, Inc. | ||
* | ||
* 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 io.aexp.nodes.graphql.models; | ||
|
||
import java.time.OffsetDateTime; | ||
|
||
public class TestModelDateTime { | ||
private OffsetDateTime dateTime; | ||
|
||
public OffsetDateTime getDateTime() { | ||
return dateTime; | ||
} | ||
|
||
public void setDateTime(OffsetDateTime dateTime) { | ||
this.dateTime = dateTime; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TestModelDateTime{" + "dateTime='" + dateTime + '\'' + '}'; | ||
} | ||
} |