@Test public void testSerialize() throws SAXException, IOException { BatchJobMutateRequest mutate = new BatchJobMutateRequest(); List<Operation> ops = Lists.newArrayList(); Campaign campaign = new Campaign(); campaign.setId(-1L); campaign.setName("Test campaign"); campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH); ops.add(new CampaignOperation(Operator.ADD, "ADD", campaign)); AdGroup adGroup = new AdGroup(); adGroup.setName("Test ad group"); adGroup.setCampaignId(campaign.getId()); ops.add(new AdGroupOperation(Operator.ADD, "ADD", adGroup)); mutate.setOperations(ops.toArray(new Operation[0])); AxisSerializer serializer = new AxisSerializer(); StringWriter writer = new StringWriter(); SerializationContext context = new SerializationContext(writer); context.setSendDecl(true); context.setPretty(true); serializer.serialize(mutate, context); String serializedRequest = writer.toString(); assertNotNull("Serialized request is null", serializedRequest); String expectedSerializedRequest = CharStreams.toString( new InputStreamReader( AxisSerializerTest.class.getResourceAsStream( "resources/BatchJobMutate.request.xml"), UTF_8)); XMLAssert.assertXMLEqual("Serialized request does not match expected XML", expectedSerializedRequest, serializedRequest); }
public <T extends Serializable> void serialize( T objectToSerialize, SerializationContext serializationContext) { try { QName xmlType = getXmlType(objectToSerialize.getClass()); getSerializer(xmlType, objectToSerialize.getClass()) .serialize(xmlType, null, objectToSerialize, serializationContext); } catch (RuntimeException | IOException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException("Failed to serialize: " + objectToSerialize, e); } }
AxisSerializer { public <T extends Serializable> void serialize( T objectToSerialize, SerializationContext serializationContext) { try { QName xmlType = getXmlType(objectToSerialize.getClass()); getSerializer(xmlType, objectToSerialize.getClass()) .serialize(xmlType, null, objectToSerialize, serializationContext); } catch (RuntimeException | IOException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException("Failed to serialize: " + objectToSerialize, e); } } }
AxisSerializer { public <T extends Serializable> void serialize( T objectToSerialize, SerializationContext serializationContext) { try { QName xmlType = getXmlType(objectToSerialize.getClass()); getSerializer(xmlType, objectToSerialize.getClass()) .serialize(xmlType, null, objectToSerialize, serializationContext); } catch (RuntimeException | IOException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException("Failed to serialize: " + objectToSerialize, e); } }  }
AxisSerializer { public <T extends Serializable> void serialize( T objectToSerialize, SerializationContext serializationContext) { try { QName xmlType = getXmlType(objectToSerialize.getClass()); getSerializer(xmlType, objectToSerialize.getClass()) .serialize(xmlType, null, objectToSerialize, serializationContext); } catch (RuntimeException | IOException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException("Failed to serialize: " + objectToSerialize, e); } }  void serialize(
      T objectToSerialize, SerializationContext serializationContext); }
AxisSerializer { public <T extends Serializable> void serialize( T objectToSerialize, SerializationContext serializationContext) { try { QName xmlType = getXmlType(objectToSerialize.getClass()); getSerializer(xmlType, objectToSerialize.getClass()) .serialize(xmlType, null, objectToSerialize, serializationContext); } catch (RuntimeException | IOException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException("Failed to serialize: " + objectToSerialize, e); } }  void serialize(
      T objectToSerialize, SerializationContext serializationContext);  }