-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update necessary if shadow cleared
- Loading branch information
1 parent
e97c818
commit 64ee734
Showing
5 changed files
with
131 additions
and
2 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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/aws/greengrass/shadowmanager/model/ShadowDocumentDeserializer.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,40 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.aws.greengrass.shadowmanager.model; | ||
|
||
import com.aws.greengrass.util.SerializerFactory; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
|
||
import java.io.IOException; | ||
|
||
public class ShadowDocumentDeserializer extends JsonDeserializer<ShadowDocument> { | ||
// hack to prevent StackOverflowException for custom deserialize, | ||
// allows us to use jackson's default deserialization for type within | ||
// a custom deserializer | ||
static { | ||
SerializerFactory.getFailSafeJsonObjectMapper().addMixIn(ShadowDocument.class, DefaultJsonDeserializer.class); | ||
} | ||
|
||
@JsonDeserialize | ||
private interface DefaultJsonDeserializer { | ||
// Reset default json deserializer | ||
} | ||
|
||
@Override | ||
public ShadowDocument deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
|
||
ShadowDocument document = ctxt.readValue(p, ShadowDocument.class); | ||
if (document.getState() == null) { // handle {"state": null} document | ||
ShadowDocument clearDocument = new ShadowDocument(document); | ||
clearDocument.getState().setClear(true); | ||
return clearDocument; | ||
} | ||
return document; | ||
} | ||
} |
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