-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import / Export related fixes (#3745)
Co-authored-by: kbirk <[email protected]>
- Loading branch information
Showing
15 changed files
with
187 additions
and
25 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
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
...ava/software/uncharted/terarium/hmiserver/models/dataservice/AssetExportDeserializer.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 software.uncharted.terarium.hmiserver.models.dataservice; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import software.uncharted.terarium.hmiserver.models.TerariumAsset; | ||
|
||
public class AssetExportDeserializer extends JsonDeserializer<AssetExport> { | ||
|
||
@Override | ||
public AssetExport deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { | ||
ObjectMapper mapper = (ObjectMapper) jp.getCodec(); | ||
JsonNode node = mapper.readTree(jp); | ||
|
||
final String assetTypeStr = node.get("type").asText(); | ||
final AssetType assetType = AssetType.getAssetType(assetTypeStr, mapper); | ||
|
||
TerariumAsset asset = mapper.treeToValue(node.get("asset"), assetType.getAssetClass()); | ||
|
||
Map<String, FileExport> files = new HashMap<>(); | ||
if (node.has("files")) { | ||
files = mapper.convertValue(node.get("files"), new TypeReference<Map<String, FileExport>>() {}); | ||
} | ||
|
||
AssetExport export = new AssetExport(); | ||
export.setType(assetType); | ||
export.setAsset(asset); | ||
export.setFiles(files); | ||
return export; | ||
} | ||
} |
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
...ava/software/uncharted/terarium/hmiserver/models/dataservice/ContentTypeDeserializer.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 @@ | ||
package software.uncharted.terarium.hmiserver.models.dataservice; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import org.apache.http.entity.ContentType; | ||
|
||
public class ContentTypeDeserializer extends JsonDeserializer<ContentType> { | ||
|
||
@Override | ||
public ContentType deserialize(final JsonParser jp, final DeserializationContext ctxt) | ||
throws IOException, JsonProcessingException { | ||
|
||
final ObjectMapper mapper = (ObjectMapper) jp.getCodec(); | ||
final JsonNode node = mapper.readTree(jp); | ||
|
||
final String mimeTypeStr = node.get("mimeType").asText(); | ||
if (!node.has("charset")) { | ||
return ContentType.create(mimeTypeStr); | ||
} | ||
|
||
final String charsetStr = node.get("charset").asText(); | ||
final Charset charset = Charset.forName(charsetStr); | ||
return ContentType.create(mimeTypeStr, charset); | ||
} | ||
} |
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
Oops, something went wrong.