2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.adapters.tenantrest;
26 import java.io.ByteArrayOutputStream;
27 import java.io.Serializable;
28 import javax.xml.bind.JAXBContext;
29 import javax.xml.bind.Marshaller;
30 import com.fasterxml.jackson.databind.ObjectMapper;
31 import com.fasterxml.jackson.databind.SerializationFeature;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public abstract class TenantRequestCommon implements Serializable {
37 private static final long serialVersionUID = 1486834308868170854L;
38 private static Logger logger = LoggerFactory.getLogger(TenantRequestCommon.class);
40 public String toJsonString() {
43 ObjectMapper mapper = new ObjectMapper();
44 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
45 jsonString = mapper.writeValueAsString(this);
47 } catch (Exception e) {
48 logger.debug("Exception :", e);
53 public String toXmlString() {
55 ByteArrayOutputStream bs = new ByteArrayOutputStream();
56 JAXBContext context = JAXBContext.newInstance(this.getClass());
57 Marshaller marshaller = context.createMarshaller();
58 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // pretty print XML
59 marshaller.marshal(this, bs);
61 } catch (Exception e) {
62 logger.debug("Exception :", e);