001/* 002 * Copyright 2018 Leibniz-Institut für Analytische Wissenschaften – ISAS – e.V.. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package de.isas.mztab2.io.serialization; 017 018import com.fasterxml.jackson.core.JsonGenerator; 019import com.fasterxml.jackson.databind.SerializerProvider; 020import com.fasterxml.jackson.databind.jsontype.TypeSerializer; 021import com.fasterxml.jackson.databind.ser.std.StdSerializer; 022import static de.isas.mztab2.io.serialization.Serializers.addSubElementStrings; 023import de.isas.mztab2.model.Software; 024import java.io.IOException; 025import lombok.extern.slf4j.Slf4j; 026import uk.ac.ebi.pride.jmztab2.model.Section; 027 028/** 029* <p>SoftwareSerializer implementation for {@link de.isas.mztab2.model.Software}.</p> 030 * 031 * @author nilshoffmann 032 * 033 */ 034@Slf4j 035public class SoftwareSerializer extends StdSerializer<Software> { 036 037 /** 038 * <p> 039 * Constructor for SoftwareSerializer.</p> 040 */ 041 public SoftwareSerializer() { 042 this(null); 043 } 044 045 /** 046 * <p> 047 * Constructor for SoftwareSerializer.</p> 048 * 049 * @param t a {@link java.lang.Class} object. 050 */ 051 public SoftwareSerializer(Class<Software> t) { 052 super(t); 053 } 054 055 @Override 056 public void serializeWithType(Software value, JsonGenerator gen, 057 SerializerProvider serializers, TypeSerializer typeSer) throws IOException { 058 typeSer.writeTypePrefixForObject(value, gen); 059 serialize(value, gen, serializers); 060 typeSer.writeTypeSuffixForObject(value, gen); 061 } 062 063 /** 064 * {@inheritDoc} 065 */ 066 @Override 067 public void serialize(Software software, JsonGenerator jg, 068 SerializerProvider sp) throws IOException { 069 if (software != null) { 070 Serializers.checkIndexedElement(software); 071 Serializers.addIndexedLine(jg, sp, Section.Metadata.getPrefix(), 072 software, 073 software.getParameter()); 074 addSubElementStrings(jg, Section.Metadata.getPrefix(), software, 075 Software.Properties.setting.getPropertyName(), 076 software.getSetting(), false); 077 } else { 078 log.debug(Software.class.getSimpleName() + " is null!"); 079 } 080 } 081}