Commit e5e6cab0 authored by Matija Obreza's avatar Matija Obreza
Browse files

Prevent crash on taxGenus null value

Included stub code for AccessionSerializer
parent ba6fe73e
......@@ -234,7 +234,7 @@ public class Accession extends VersionedAuditedModel {
}
public long getTaxGenus() {
return taxGenus;
return taxGenus == null ? -1 : taxGenus.longValue();
}
// TODO Must be long
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest.serialization;
import java.io.IOException;
import org.genesys2.server.model.genesys.Accession;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
// FIXME not used
public class AccessionSerializer extends JsonSerializer<Accession> {
@Override
public void serialize(Accession accession, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException {
if (accession == null) {
jgen.writeNull();
} else {
jgen.writeStartObject();
jgen.writeObjectField("id", accession.getId());
jgen.writeObjectField("version", accession.getVersion());
jgen.writeStringField("accessionName", accession.getAccessionName());
jgen.writeObjectField("countryOfOrigin", accession.getCountryOfOrigin());
jgen.writeObjectField("taxonomy", accession.getTaxonomy());
jgen.writeObjectField("institute", accession.getInstitute());
jgen.writeEndObject();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment