@Test @SuppressWarnings("unchecked") public void serializeRequest_RequestWithCollectionPayload_ShouldCallSerializeCollectionInstance() { final List<Object> collectionInstance = Arrays.asList(new Object(), new Object()); final String mediaType = "don't/matter"; Request request = mock(Request.class); when(request.getPayload()).thenReturn(collectionInstance); when(request.getContentType()).thenReturn(mediaType); Serializer serializer = mock(Serializer.class); when(serdesManager.getSerializer(collectionInstance.get(0).getClass(), mediaType)).thenReturn(serializer); engine.serializeRequest(request); verify(serdesManager).getSerializer(collectionInstance.get(0).getClass(), mediaType); verify(serializer, never()).serialize(anyObject(), any(SerializationContext.class)); verify(serializer).serialize(eq(collectionInstance), any(SerializationContext.class)); }
public SerializedRequestDelegate serializeRequest(Request request) { Object payload = request.getPayload(); String body = null; if (payload != null) { final String mediaType = getRequestMediaType(request); if (payload instanceof Collection) { Collection c = (Collection) payload; final Iterator iterator = c.iterator(); Object item = null; while (iterator.hasNext() && item == null) { item = iterator.next(); } if (item == null) { body = isJsonMediaType(mediaType) ? "[]" : ""; } else { Serializer<?> serializer = serdesManager.getSerializer(item.getClass(), mediaType); checkSerializerNotNull(request, item.getClass(), serializer); body = serializer.serialize(c, new HttpSerializationContext(request)); } } else { @SuppressWarnings("unchecked") Serializer<Object> serializer = (Serializer<Object>) serdesManager.getSerializer(payload.getClass(), mediaType); checkSerializerNotNull(request, payload.getClass(), serializer); body = serializer.serialize(payload, new HttpSerializationContext(request)); } } return new SerializedRequestDelegate(request, new Payload(body)); }
SerializationEngine { public SerializedRequestDelegate serializeRequest(Request request) { Object payload = request.getPayload(); String body = null; if (payload != null) { final String mediaType = getRequestMediaType(request); if (payload instanceof Collection) { Collection c = (Collection) payload; final Iterator iterator = c.iterator(); Object item = null; while (iterator.hasNext() && item == null) { item = iterator.next(); } if (item == null) { body = isJsonMediaType(mediaType) ? "[]" : ""; } else { Serializer<?> serializer = serdesManager.getSerializer(item.getClass(), mediaType); checkSerializerNotNull(request, item.getClass(), serializer); body = serializer.serialize(c, new HttpSerializationContext(request)); } } else { @SuppressWarnings("unchecked") Serializer<Object> serializer = (Serializer<Object>) serdesManager.getSerializer(payload.getClass(), mediaType); checkSerializerNotNull(request, payload.getClass(), serializer); body = serializer.serialize(payload, new HttpSerializationContext(request)); } } return new SerializedRequestDelegate(request, new Payload(body)); } }
SerializationEngine { public SerializedRequestDelegate serializeRequest(Request request) { Object payload = request.getPayload(); String body = null; if (payload != null) { final String mediaType = getRequestMediaType(request); if (payload instanceof Collection) { Collection c = (Collection) payload; final Iterator iterator = c.iterator(); Object item = null; while (iterator.hasNext() && item == null) { item = iterator.next(); } if (item == null) { body = isJsonMediaType(mediaType) ? "[]" : ""; } else { Serializer<?> serializer = serdesManager.getSerializer(item.getClass(), mediaType); checkSerializerNotNull(request, item.getClass(), serializer); body = serializer.serialize(c, new HttpSerializationContext(request)); } } else { @SuppressWarnings("unchecked") Serializer<Object> serializer = (Serializer<Object>) serdesManager.getSerializer(payload.getClass(), mediaType); checkSerializerNotNull(request, payload.getClass(), serializer); body = serializer.serialize(payload, new HttpSerializationContext(request)); } } return new SerializedRequestDelegate(request, new Payload(body)); } SerializationEngine(SerdesManagerImpl serdesManager, ProviderManagerImpl providerManager); }
SerializationEngine { public SerializedRequestDelegate serializeRequest(Request request) { Object payload = request.getPayload(); String body = null; if (payload != null) { final String mediaType = getRequestMediaType(request); if (payload instanceof Collection) { Collection c = (Collection) payload; final Iterator iterator = c.iterator(); Object item = null; while (iterator.hasNext() && item == null) { item = iterator.next(); } if (item == null) { body = isJsonMediaType(mediaType) ? "[]" : ""; } else { Serializer<?> serializer = serdesManager.getSerializer(item.getClass(), mediaType); checkSerializerNotNull(request, item.getClass(), serializer); body = serializer.serialize(c, new HttpSerializationContext(request)); } } else { @SuppressWarnings("unchecked") Serializer<Object> serializer = (Serializer<Object>) serdesManager.getSerializer(payload.getClass(), mediaType); checkSerializerNotNull(request, payload.getClass(), serializer); body = serializer.serialize(payload, new HttpSerializationContext(request)); } } return new SerializedRequestDelegate(request, new Payload(body)); } SerializationEngine(SerdesManagerImpl serdesManager, ProviderManagerImpl providerManager); Response<C> deserializeResponse(Request request,
                                                                        SerializedResponse response,
                                                                        Class<T> type,
                                                                        Class<C> containerType); Response<T> deserializeResponse(Request request, SerializedResponse response, Class<T> type); SerializedRequestDelegate serializeRequest(Request request); }
SerializationEngine { public SerializedRequestDelegate serializeRequest(Request request) { Object payload = request.getPayload(); String body = null; if (payload != null) { final String mediaType = getRequestMediaType(request); if (payload instanceof Collection) { Collection c = (Collection) payload; final Iterator iterator = c.iterator(); Object item = null; while (iterator.hasNext() && item == null) { item = iterator.next(); } if (item == null) { body = isJsonMediaType(mediaType) ? "[]" : ""; } else { Serializer<?> serializer = serdesManager.getSerializer(item.getClass(), mediaType); checkSerializerNotNull(request, item.getClass(), serializer); body = serializer.serialize(c, new HttpSerializationContext(request)); } } else { @SuppressWarnings("unchecked") Serializer<Object> serializer = (Serializer<Object>) serdesManager.getSerializer(payload.getClass(), mediaType); checkSerializerNotNull(request, payload.getClass(), serializer); body = serializer.serialize(payload, new HttpSerializationContext(request)); } } return new SerializedRequestDelegate(request, new Payload(body)); } SerializationEngine(SerdesManagerImpl serdesManager, ProviderManagerImpl providerManager); Response<C> deserializeResponse(Request request,
                                                                        SerializedResponse response,
                                                                        Class<T> type,
                                                                        Class<C> containerType); Response<T> deserializeResponse(Request request, SerializedResponse response, Class<T> type); SerializedRequestDelegate serializeRequest(Request request);  }