mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-18 05:22:10 +01:00
Fix deserialization of embedded values in HAL objects (#1630)
The embedded avatar object of the repository avatar plugin leads to an exception without this configuration, when a repository json object is deserialized. This happens for example when the description of a repository should be modified.
This commit is contained in:
3
gradle/changelog/embedded_deserialization.yaml
Normal file
3
gradle/changelog/embedded_deserialization.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
- type: fixed
|
||||
description: Deserialization of embedded values in HAL objects ([#1630](https://github.com/scm-manager/scm-manager/pull/1630))
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.rest;
|
||||
|
||||
import com.fasterxml.jackson.databind.AnnotationIntrospector;
|
||||
@@ -50,6 +50,7 @@ public class ObjectMapperProvider implements Provider<ObjectMapper> {
|
||||
mapper.setAnnotationIntrospector(createAnnotationIntrospector());
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||
mapper.configure(SerializationFeature.WRITE_DATES_WITH_ZONE_ID, true);
|
||||
mapper.setDateFormat(new StdDateFormat());
|
||||
return mapper;
|
||||
|
||||
@@ -21,10 +21,11 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.rest;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.ZoneId;
|
||||
@@ -45,4 +46,10 @@ class ObjectMapperProviderTest {
|
||||
assertThat(value).isEqualTo("\"2020-02-04T14:21:42Z\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDeserializeEmbeddedObjects() throws JsonProcessingException {
|
||||
HalRepresentation halRepresentation = provider.get().readValue("{\"_embedded\": {\"avatar\": {\"type\": \"AUTO_GENERATED\"}}}", HalRepresentation.class);
|
||||
|
||||
assertThat(halRepresentation.getEmbedded().getItemsBy("avatar")).hasSize(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user