Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.openmrs.module.openconceptlab.client.Deserializer;

import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;

import java.io.IOException;

public class StringBooleanDeserializer extends JsonDeserializer<Boolean> {

@Override
public Boolean deserialize(JsonParser parser, DeserializationContext context)
throws IOException {
return Boolean.parseBoolean(parser.getText());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.module.openconceptlab.client.Deserializer.StringBooleanDeserializer;

@JsonIgnoreProperties(ignoreUnknown = true)
public class OclConcept {
Expand All @@ -43,6 +45,7 @@ public class OclConcept {

private List<Description> descriptions = new ArrayList<>();

@JsonProperty
private boolean retired;

private String url;
Expand Down Expand Up @@ -131,6 +134,7 @@ public boolean isRetired() {
return retired;
}

@JsonDeserialize(using = StringBooleanDeserializer.class)
public void setRetired(boolean retired) {
this.retired = retired;
}
Expand Down Expand Up @@ -461,6 +465,7 @@ public Boolean getPrecise() {
return precise;
}

@JsonDeserialize(using = StringBooleanDeserializer.class)
public void setPrecise(Boolean precise) {
this.precise = precise;
}
Expand All @@ -471,4 +476,5 @@ public void setPrecise(Boolean precise) {
public String toString() {
return new ToStringBuilder(this).append("externalId", externalId).build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.openmrs.module.openconceptlab.client.Deserializer;

import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Test;
import org.openmrs.module.openconceptlab.client.OclConcept;

import java.io.IOException;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class StringBooleanDeserializerTest {
@Test
public void stringBooleanDeserializer_shouldDeserialiseBooleanString()
throws IOException {
ObjectMapper mapper = new ObjectMapper();
OclConcept oclConcept = mapper.readValue("{"
+ "\"id\":467179,"
+ "\"public access\":\"Edit\","
+ "\"created at\":\"2021-10-01T13:50:28.293664+00:00\","
+ "\"updated at\":\"2021-10-01T13:50:28.302355+00:00\","
+ "\"created_by_id\":789,"
+ "\"updated_by_id\":789,"
+ "\"is active\":\"True\","
+ "\"extras\": {"
+ " \"precise\": \"TRUE\""
+ "},"
+ "\"uri\": \"/orgs/MSFOCP/sources/OCL-CSV-Import-Test/concepts/OCLCSV07/467179/\","
+ "\"version\": 467179,"
+ "\"released\": \"True\","
+ "\"retired\": \"False\","
+ "\"is latest version\": \"False\","
+ "\"name\": \"\","
+ "\"full name\": \"\","
+ "\"default locale\": \"en\","
+ "\"supported locales\": \"\","
+ "\"website\": \"\","
+ "\"description\": \"\""
+ "}",OclConcept.class);

assertThat(oclConcept.getExtras().getPrecise(), is(true));
assertThat(oclConcept.isRetired(), is(false));
}
}