001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF 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 007 * the 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, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.model.dataformat; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023import javax.xml.bind.annotation.XmlTransient; 024 025import org.apache.camel.CamelContext; 026import org.apache.camel.model.DataFormatDefinition; 027import org.apache.camel.spi.DataFormat; 028import org.apache.camel.spi.Metadata; 029import org.apache.camel.spi.RouteContext; 030import org.apache.camel.util.ObjectHelper; 031 032/** 033 * Boon data format is used for unmarshal a JSon payload to POJO or to marshal POJO back to JSon payload. 034 */ 035@Metadata(firstVersion = "2.16.0", label = "dataformat,transformation,json", title = "Boon", 036 deprecationNode = "Not functional in Java 9+ and will be removed in Apache Camel 3.0.0") 037@XmlRootElement(name = "boon") 038@XmlAccessorType(XmlAccessType.FIELD) 039@Deprecated 040public class BoonDataFormat extends DataFormatDefinition { 041 042 @XmlAttribute(required = true) 043 private String unmarshalTypeName; 044 @XmlTransient 045 private Class<?> unmarshalType; 046 @XmlAttribute 047 private Boolean useList; 048 049 public BoonDataFormat() { 050 super("boon"); 051 } 052 053 public BoonDataFormat(Class<?> unmarshalType) { 054 this(); 055 setUnmarshalType(unmarshalType); 056 } 057 058 public Class<?> getUnmarshalType() { 059 return unmarshalType; 060 } 061 062 /** 063 * Class name of the java type to use when unarmshalling 064 */ 065 public void setUnmarshalType(Class<?> unmarshalType) { 066 this.unmarshalType = unmarshalType; 067 } 068 069 public String getUnmarshalTypeName() { 070 return unmarshalTypeName; 071 } 072 073 /** 074 * Class name of the java type to use when unarmshalling 075 */ 076 public void setUnmarshalTypeName(String unmarshalTypeName) { 077 this.unmarshalTypeName = unmarshalTypeName; 078 } 079 080 public boolean isUseList() { 081 return useList; 082 } 083 084 /** 085 * To unarmshal to a List of Map or a List of Pojo. 086 */ 087 public void setUseList(boolean useList) { 088 this.useList = useList; 089 } 090 091 @Override 092 protected DataFormat createDataFormat(RouteContext routeContext) { 093 if (unmarshalType == null && unmarshalTypeName != null) { 094 try { 095 unmarshalType = routeContext.getCamelContext().getClassResolver().resolveMandatoryClass(unmarshalTypeName); 096 } catch (ClassNotFoundException e) { 097 throw ObjectHelper.wrapRuntimeCamelException(e); 098 } 099 } 100 return super.createDataFormat(routeContext); 101 } 102 103 @Override 104 protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) { 105 if (unmarshalType != null) { 106 setProperty(camelContext, dataFormat, "unmarshalType", unmarshalType); 107 } 108 if (useList != null) { 109 setProperty(camelContext, dataFormat, "useList", useList); 110 } 111 } 112}