diff --git a/sdk/src/main/java/org/hisp/dhis/integration/sdk/DefaultDhis2Client.java b/sdk/src/main/java/org/hisp/dhis/integration/sdk/DefaultDhis2Client.java index a645430..3fd67dc 100644 --- a/sdk/src/main/java/org/hisp/dhis/integration/sdk/DefaultDhis2Client.java +++ b/sdk/src/main/java/org/hisp/dhis/integration/sdk/DefaultDhis2Client.java @@ -93,7 +93,7 @@ public PatchOperation patch( String path, String... pathParams ) @Override public DeleteOperation delete( String path, String... pathParams ) { - return new DefaultDeleteOperation( apiUrl, path, httpClient, converterFactory ); + return new DefaultDeleteOperation( apiUrl, path, httpClient, converterFactory, pathParams ); } @Override diff --git a/sdk/src/main/java/org/hisp/dhis/integration/sdk/api/converter/ConverterFactory.java b/sdk/src/main/java/org/hisp/dhis/integration/sdk/api/converter/ConverterFactory.java index eea1247..786b559 100644 --- a/sdk/src/main/java/org/hisp/dhis/integration/sdk/api/converter/ConverterFactory.java +++ b/sdk/src/main/java/org/hisp/dhis/integration/sdk/api/converter/ConverterFactory.java @@ -29,7 +29,7 @@ public interface ConverterFactory { - RequestConverter createRequestConverter( Object requestType ); + RequestConverter createRequestConverter( Class requestType ); ResponseConverter createResponseConverter( Class responseType ); } diff --git a/sdk/src/main/java/org/hisp/dhis/integration/sdk/api/converter/RequestConverter.java b/sdk/src/main/java/org/hisp/dhis/integration/sdk/api/converter/RequestConverter.java index c4a5e68..c446585 100644 --- a/sdk/src/main/java/org/hisp/dhis/integration/sdk/api/converter/RequestConverter.java +++ b/sdk/src/main/java/org/hisp/dhis/integration/sdk/api/converter/RequestConverter.java @@ -27,7 +27,7 @@ */ package org.hisp.dhis.integration.sdk.api.converter; -public interface RequestConverter +public interface RequestConverter { - String convert( Object requestBody ); + String convert( T requestBody ); } diff --git a/sdk/src/main/java/org/hisp/dhis/integration/sdk/internal/converter/JacksonConverterFactory.java b/sdk/src/main/java/org/hisp/dhis/integration/sdk/internal/converter/JacksonConverterFactory.java index 1e09241..2b900ee 100644 --- a/sdk/src/main/java/org/hisp/dhis/integration/sdk/internal/converter/JacksonConverterFactory.java +++ b/sdk/src/main/java/org/hisp/dhis/integration/sdk/internal/converter/JacksonConverterFactory.java @@ -34,9 +34,9 @@ public class JacksonConverterFactory implements ConverterFactory { @Override - public RequestConverter createRequestConverter( Object requestType ) + public RequestConverter createRequestConverter( Class requestType ) { - return new JacksonRequestConverter(); + return new JacksonRequestConverter<>(requestType); } @Override diff --git a/sdk/src/main/java/org/hisp/dhis/integration/sdk/internal/converter/JacksonRequestConverter.java b/sdk/src/main/java/org/hisp/dhis/integration/sdk/internal/converter/JacksonRequestConverter.java index 3870557..935ad39 100644 --- a/sdk/src/main/java/org/hisp/dhis/integration/sdk/internal/converter/JacksonRequestConverter.java +++ b/sdk/src/main/java/org/hisp/dhis/integration/sdk/internal/converter/JacksonRequestConverter.java @@ -27,25 +27,32 @@ */ package org.hisp.dhis.integration.sdk.internal.converter; -import org.hisp.dhis.integration.sdk.api.converter.RequestConverter; - -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import org.hisp.dhis.integration.sdk.api.converter.RequestConverter; + +import java.io.IOException; -public class JacksonRequestConverter implements RequestConverter +public class JacksonRequestConverter implements RequestConverter { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().registerModule( new Jdk8Module().configureAbsentsAsNulls( true ) ); + private final Class requestType; + + public JacksonRequestConverter( Class requestType ) + { + this.requestType = requestType; + } + @Override - public String convert( Object requestBody ) + public String convert( T requestBody ) { try { return OBJECT_MAPPER.writeValueAsString( requestBody ); } - catch ( JsonProcessingException e ) + catch ( IOException e ) { throw new RuntimeException( e ); } diff --git a/sdk/src/main/java/org/hisp/dhis/integration/sdk/internal/operation/AbstractResourceOperation.java b/sdk/src/main/java/org/hisp/dhis/integration/sdk/internal/operation/AbstractResourceOperation.java index cc6d116..f3b356e 100644 --- a/sdk/src/main/java/org/hisp/dhis/integration/sdk/internal/operation/AbstractResourceOperation.java +++ b/sdk/src/main/java/org/hisp/dhis/integration/sdk/internal/operation/AbstractResourceOperation.java @@ -60,7 +60,7 @@ public Dhis2Response doTransfer( HttpUrl httpUrl ) } else { - bytes = converterFactory.createRequestConverter( requestBuilder.build() ).convert( resource ) + bytes = converterFactory.createRequestConverter( (Class) resource.getClass() ).convert( resource ) .getBytes(); } }