Skip to content

Commit

Permalink
LNK-1524: fix validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
arianamihailescu committed Feb 1, 2024
1 parent 10a140c commit 0d33d20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package com.lantanagroup.link.serialize;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.IParser;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;

import java.io.IOException;

public class FhirJsonDeserializer<T> extends JsonDeserializer<T> {
private IParser jsonParser;
private final IParser jsonParser;

public FhirJsonDeserializer(IParser jsonParser) {
this.jsonParser = jsonParser;
}

@Override
public T deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
String jsonContent = jsonParser.readValueAsTree().toString();
return (T) this.jsonParser.parseResource(jsonContent);
public T deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) {
try {
String jsonContent = jsonParser.readValueAsTree().toString();
return (T) this.jsonParser.parseResource(jsonContent);
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.lantanagroup.link.spring;

import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import com.auth0.jwk.JwkException;
import com.auth0.jwt.exceptions.JWTVerificationException;
Expand Down Expand Up @@ -74,10 +73,6 @@ private boolean resolve(HttpServletResponse response, Throwable throwable) throw
response.sendError(exception.getStatusCode(), exception.getReasonPhrase());
return true;
}
if(throwable instanceof DataFormatException) {
response.sendError(400, throwable.getMessage());
return true;
}
return false;
}

Expand Down

0 comments on commit 0d33d20

Please sign in to comment.