001package io.konik.sdk; 002 003import com.fasterxml.jackson.core.JsonParser; 004import com.fasterxml.jackson.databind.DeserializationContext; 005import com.fasterxml.jackson.databind.DeserializationFeature; 006import com.fasterxml.jackson.databind.JsonDeserializer; 007import com.fasterxml.jackson.databind.ObjectMapper; 008import com.fasterxml.jackson.databind.module.SimpleModule; 009import io.konik.Configuration; 010import io.konik.zugferd.unqualified.ZfDate; 011import io.konik.zugferd.unqualified.ZfDateDay; 012 013import java.io.IOException; 014 015/** 016 * Main SDK configuration class. 017 */ 018public class ZinvoiceApiConfig { 019 020 /** 021 * Zinvoice user API KEY 022 */ 023 private final String apiKey; 024 025 /** 026 * Absolute URL to Zinvoice remote service. 027 * 028 * e.g. https://app.z-rechnung.com 029 */ 030 private final String destinationUrl; 031 032 public ZinvoiceApiConfig() { 033 this(Configuration.INSTANCE.getProperty("io.konik.zinvoice.api-key"), 034 Configuration.INSTANCE.getProperty("io.konik.zinvoice.url")); 035 } 036 037 public ZinvoiceApiConfig(String apiKey, String destinationUrl) { 038 this.apiKey = apiKey; 039 this.destinationUrl = destinationUrl; 040 } 041 042 public String getApiKey() { 043 return apiKey; 044 } 045 046 public String getDestinationUrl() { 047 return destinationUrl; 048 } 049 050 public ObjectMapper getDefaulObjectMapper() { 051 SimpleModule module = new SimpleModule(); 052 module.addDeserializer(ZfDate.class, new JsonDeserializer<ZfDate>() { 053 @Override 054 public ZfDate deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { 055 Long timestamp = jp.readValueAs(Long.class); 056 return new ZfDateDay(timestamp); 057 } 058 }); 059 060 ObjectMapper objectMapper = new ObjectMapper(); 061 objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 062 objectMapper.registerModule(module); 063 return objectMapper; 064 } 065}