io.lindstrom.mpd.support.ProfilesDeserializer Maven / Gradle / Ivy
package io.lindstrom.mpd.support;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import io.lindstrom.mpd.data.Profile;
import io.lindstrom.mpd.data.Profiles;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ProfilesDeserializer extends JsonDeserializer {
@Override
public Profiles deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
String text = p.getText();
List profiles = new ArrayList<>();
List others = new ArrayList<>();
for (String identifier : text.split(",")) {
identifier = identifier.trim();
try {
profiles.add(Profile.fromIdentifier(identifier));
} catch (IllegalArgumentException e) {
others.add(identifier);
}
}
return new Profiles(profiles, others);
}
}