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.juneau.bean.jsonapi; 018 019import static org.apache.juneau.commons.utils.CollectionUtils.*; 020import static org.apache.juneau.commons.utils.Shorts.*; 021 022import java.util.*; 023 024import org.apache.juneau.marshall.*; 025import org.apache.juneau.marshall.marshaller.*; 026 027/** 028 * Represents the JSON:API top-level {@code jsonapi} member. 029 * 030 * <p> 031 * Per <a href="https://jsonapi.org/format/#document-jsonapi-object">JSON:API v1.1 § JSON:API Object</a>, 032 * this object carries the optional protocol {@code version} string (e.g. {@code "1.1"}) and an optional 033 * {@code meta} bag. 034 * 035 * <h5 class='section'>See Also:</h5><ul> 036 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanJsonApi">juneau-bean-jsonapi</a> 037 * </ul> 038 */ 039@Marshalled 040public class JsonApiVersion { 041 042 private String version; 043 private Map<String,Object> meta; 044 045 /** 046 * Default constructor. 047 */ 048 public JsonApiVersion() {} 049 050 /** 051 * Convenience constructor. 052 * 053 * @param version The JSON:API protocol version (e.g. {@code "1.1"}). Can be <jk>null</jk> to leave the property unset. 054 */ 055 public JsonApiVersion(String version) { 056 this.version = version; 057 } 058 059 /** 060 * Bean property getter: <property>version</property>. 061 * 062 * @return The value of the <property>version</property> property, or <jk>null</jk> if it is not set. 063 */ 064 public String getVersion() { return version; } 065 066 /** 067 * Bean property setter: <property>version</property>. 068 * 069 * @param value The new value for this property. Can be <jk>null</jk> to unset the property. 070 * @return This object. 071 */ 072 public JsonApiVersion setVersion(String value) { 073 version = value; 074 return this; 075 } 076 077 /** 078 * Bean property getter: <property>meta</property>. 079 * 080 * @return The value of the <property>meta</property> property, or <jk>null</jk> if it is not set. 081 */ 082 public Map<String,Object> getMeta() { return u(meta); } 083 084 /** 085 * Bean property setter: <property>meta</property>. 086 * 087 * @param value The new value for this property. Can be <jk>null</jk> to unset the property. 088 * @return This object. 089 */ 090 public JsonApiVersion setMeta(Map<String,Object> value) { 091 meta = value; 092 return this; 093 } 094 095 /** 096 * Convenience method to add a single meta entry. 097 * 098 * @param name The meta key. Can be <jk>null</jk> ({@link LinkedHashMap} tolerates a <jk>null</jk> key). 099 * @param value The meta value. Can be <jk>null</jk> (stored as <jk>null</jk>). 100 * @return This object. 101 */ 102 public JsonApiVersion putMeta(String name, Object value) { 103 if (meta == null) 104 meta = map(); 105 meta.put(name, value); 106 return this; 107 } 108 109 @Override /* Overridden from Object */ 110 public String toString() { 111 return Json.of(this); 112 } 113}