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 de.isas.mztab2.model.SampleProcessing; 023import java.io.IOException; 024import lombok.extern.slf4j.Slf4j; 025import uk.ac.ebi.pride.jmztab2.model.Section; 026 027/** 028 * <p>SampleProcessingSerializer implementation for {@link de.isas.mztab2.model.SampleProcessing}.</p> 029 * 030 * @author nilshoffmann 031 * 032 */ 033@Slf4j 034public class SampleProcessingSerializer extends StdSerializer<SampleProcessing> { 035 036 /** 037 * <p>Constructor for SampleProcessingSerializer.</p> 038 */ 039 public SampleProcessingSerializer() { 040 this(null); 041 } 042 043 /** 044 * <p>Constructor for SampleProcessingSerializer.</p> 045 * 046 * @param t a {@link java.lang.Class} object. 047 */ 048 public SampleProcessingSerializer(Class<SampleProcessing> t) { 049 super(t); 050 } 051 052 @Override 053 public void serializeWithType(SampleProcessing value, JsonGenerator gen, 054 SerializerProvider serializers, TypeSerializer typeSer) throws IOException { 055 typeSer.writeTypePrefixForObject(value, gen); 056 serialize(value, gen, serializers); 057 typeSer.writeTypeSuffixForObject(value, gen); 058 } 059 060 /** {@inheritDoc} */ 061 @Override 062 public void serialize(SampleProcessing sampleProcessing, JsonGenerator jg, 063 SerializerProvider sp) throws IOException { 064 if (sampleProcessing != null) { 065 Serializers.checkIndexedElement(sampleProcessing); 066 Serializers.addIndexedLine(jg, sp, Section.Metadata.getPrefix(), 067 sampleProcessing, 068 sampleProcessing.getSampleProcessing()); 069 } else { 070 log.debug(SampleProcessing.class.getSimpleName()+" is null!"); 071 } 072 } 073}