001/*
002 * flattr4j - A Java library for Flattr
003 *
004 * Copyright (C) 2012 Richard "Shred" Körber
005 *   http://flattr4j.shredzone.org
006 *
007 * This program is free software: you can redistribute it and/or modify
008 * it under the terms of the GNU General Public License / GNU Lesser
009 * General Public License as published by the Free Software Foundation,
010 * either version 3 of the License, or (at your option) any later version.
011 *
012 * Licensed under the Apache License, Version 2.0 (the "License");
013 * you may not use this file except in compliance with the License.
014 *
015 * This program is distributed in the hope that it will be useful,
016 * but WITHOUT ANY WARRANTY; without even the implied warranty of
017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
018 */
019package org.shredzone.flattr4j.model;
020
021import java.io.Serializable;
022
023import org.shredzone.flattr4j.connector.FlattrObject;
024
025/**
026 * A generic Flattr resource.
027 *
028 * @author Richard "Shred" Körber
029 * @since 2.0
030 */
031public class Resource implements Serializable {
032    private static final long serialVersionUID = 2052931614858694519L;
033
034    protected FlattrObject data;
035
036    /**
037     * Creates a new resource.
038     *
039     * @param data
040     *            {@link FlattrObject} containing the resource data
041     */
042    public Resource(FlattrObject data) {
043        this.data = data;
044    }
045
046    /**
047     * Returns the resource contents as JSON string.
048     */
049    public String toJSON() {
050        return data.toString();
051    }
052
053    /**
054     * Returns the resource as {@link FlattrObject}, for further processing.
055     * <p>
056     * Do not use the returned {@link FlattrObject} for modifying the resource contents.
057     * The behaviour might be unpredictable.
058     */
059    public FlattrObject toFlattrObject() {
060        return data;
061    }
062
063}