001/* 002 * Copyright 2010-2014 Ning, Inc. 003 * Copyright 2014-2015 The Billing Project, LLC 004 * 005 * The Billing Project licenses this file to you under the Apache License, version 2.0 006 * (the "License"); you may not use this file except in compliance with the 007 * License. You may obtain a copy of the License at: 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 014 * License for the specific language governing permissions and limitations 015 * under the License. 016 */ 017 018package com.ning.billing.recurly.model.jackson; 019 020import java.io.IOException; 021 022import javax.xml.namespace.QName; 023 024import com.fasterxml.jackson.databind.SerializationConfig; 025import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider; 026import com.fasterxml.jackson.databind.ser.SerializerFactory; 027import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; 028import com.fasterxml.jackson.dataformat.xml.ser.XmlSerializerProvider; 029import com.fasterxml.jackson.dataformat.xml.util.XmlRootNameLookup; 030 031// Custom XmlSerializerProvider which delegates the writing of field names in array to 032// the object serializer (RecurlyObjectsSerializer). The default implementation hardcodes them to "item". 033public final class RecurlyXmlSerializerProvider extends XmlSerializerProvider { 034 035 public RecurlyXmlSerializerProvider() { 036 this(new XmlRootNameLookup()); 037 } 038 039 public RecurlyXmlSerializerProvider(final XmlRootNameLookup rootNames) { 040 super(rootNames); 041 } 042 043 public RecurlyXmlSerializerProvider(final XmlSerializerProvider src, final SerializationConfig config, final SerializerFactory f) { 044 super(src, config, f); 045 } 046 047 @Override 048 public DefaultSerializerProvider createInstance(final SerializationConfig config, final SerializerFactory jsf) { 049 return new RecurlyXmlSerializerProvider(this, config, jsf); 050 } 051 052 @Override 053 protected void _startRootArray(final ToXmlGenerator xgen, final QName rootName) throws IOException { 054 xgen.writeStartObject(); 055 } 056}