Skip to content

Commit

Permalink
Better JSON (de-)serialization.
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Sabadello <markus@danubetech.com>
  • Loading branch information
peacekeeper committed Nov 10, 2019
1 parent 81b1965 commit cba4f22
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public ResolveResult resolve(String identifier) throws ResolutionException {
}
}

didDocumentContinuation = DIDDocument.fromJson(jsonLdObject);
didDocumentContinuation = DIDDocument.build(jsonLdObject);
EntityUtils.consume(httpEntity);
} catch (IOException ex) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.xbill.DNS.Type;
import org.xbill.DNS.URIRecord;

import did.DIDDocument;
import uniresolver.ResolutionException;
import uniresolver.driver.Driver;
import uniresolver.result.ResolveResult;
Expand Down Expand Up @@ -129,7 +130,7 @@ public ResolveResult resolve(String identifier) throws ResolutionException {

// create RESOLVE RESULT

ResolveResult resolveResult = ResolveResult.build(null, null, methodMetadata);
ResolveResult resolveResult = ResolveResult.build((DIDDocument) null, null, methodMetadata);

// done

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonRawValue;
Expand All @@ -19,6 +20,7 @@
import did.DIDDocument;

@JsonPropertyOrder({ "didDocument", "resolverMetadata", "methodMetadata" })
@JsonIgnoreProperties(ignoreUnknown=true)
public class ResolveResult {

public static final String MIME_TYPE = "application/json";
Expand Down Expand Up @@ -46,12 +48,7 @@ private ResolveResult(DIDDocument didDocument, Map<String, Object> resolverMetad
*/

@JsonCreator
public static ResolveResult build() {

return new ResolveResult(null, new HashMap<String, Object> (), new HashMap<String, Object> ());
}

public static ResolveResult build(DIDDocument didDocument, Map<String, Object> resolverMetadata, Map<String, Object> methodMetadata) {
public static ResolveResult build(@JsonProperty(value="didDocument", required=true) DIDDocument didDocument, @JsonProperty(value="resolverMetadata", required=true) Map<String, Object> resolverMetadata, @JsonProperty(value="methodMetadata", required=true) Map<String, Object> methodMetadata) {

return new ResolveResult(didDocument, resolverMetadata, methodMetadata);
}
Expand All @@ -61,6 +58,16 @@ public static ResolveResult build(DIDDocument didDocument) {
return new ResolveResult(didDocument, new HashMap<String, Object> (), new HashMap<String, Object> ());
}

public static ResolveResult build(Map<String, Object> didDocument) {

return new ResolveResult(DIDDocument.build(didDocument), new HashMap<String, Object> (), new HashMap<String, Object> ());
}

public static ResolveResult build() {

return new ResolveResult(null, new HashMap<String, Object> (), new HashMap<String, Object> ());
}

public ResolveResult copy() {

return new ResolveResult(this.getDidDocument(), this.getResolverMetadata(), this.getMethodMetadata());
Expand Down Expand Up @@ -102,17 +109,12 @@ public final DIDDocument getDidDocument() {
return this.didDocument;
}

@JsonSetter
public final void setDidDocument(DIDDocument didDocument) {

this.didDocument = didDocument;
}

@JsonSetter
public final void setDidDocument(Map<String, Object> jsonLdObject) {

this.didDocument = DIDDocument.build(jsonLdObject);
}

@JsonGetter
public final Map<String, Object> getResolverMetadata() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import did.DIDDocument;
import did.DIDURL;
import did.parser.ParserException;
import uniresolver.ResolutionException;
Expand Down Expand Up @@ -228,6 +229,11 @@ public void resolveWithDrivers(String resolveIdentifier, ResolveResult resolveRe
if (log.isDebugEnabled()) log.debug("Attemping to resolve " + resolveIdentifier + " with driver " + driver.getValue().getClass());
driverResolveResult = driver.getValue().resolve(resolveIdentifier);

if (driverResolveResult != null && driverResolveResult.getDidDocument() != null && driverResolveResult.getDidDocument().getJsonLdObject().isEmpty()) {

driverResolveResult.setDidDocument((DIDDocument) null);
}

if (driverResolveResult != null) {

usedDriverId = driver.getKey();
Expand Down

0 comments on commit cba4f22

Please sign in to comment.