All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fm.last.musicbrainz.coverart.impl.ProxiedCoverArtFactory Maven / Gradle / Ivy

/*
 * Copyright 2012 Last.fm
 *
 *  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 fm.last.musicbrainz.coverart.impl;

import java.io.IOException;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;

import fm.last.musicbrainz.coverart.CoverArt;

class ProxiedCoverArtFactory {

  private final DefaultCoverArtArchiveClient client;
  private final ObjectMapper mapper;

  public ProxiedCoverArtFactory(DefaultCoverArtArchiveClient client) {
    this.client = client;
    mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  }

  public CoverArt valueOf(String json) throws IOException {
    if (Strings.isNullOrEmpty(json)) {
      return null;
    }
    CoverArtBean coverArtBean = mapper.readValue(json, CoverArtBean.class);
    return new CoverArtBeanDecorator(coverArtBean, client);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy