More Config.fromJSON method variations added. #351

pull/382/head
Nikita 9 years ago
parent ab33a099d5
commit 4762e19730

@ -15,7 +15,11 @@
*/
package org.redisson;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.net.URL;
import org.redisson.client.codec.Codec;
import org.redisson.codec.JsonJacksonCodec;
@ -335,11 +339,66 @@ public class Config {
return useLinuxNativeEpoll;
}
/**
* Read config object stored in JSON format from <code>String</code>
*
* @param content
* @return
* @throws IOException
*/
public static Config fromJSON(String content) throws IOException {
ConfigSupport support = new ConfigSupport();
return support.fromJSON(content);
}
/**
* Read config object stored in JSON format from <code>InputStream</code>
*
* @param inputStream
* @return
* @throws IOException
*/
public static Config fromJSON(InputStream inputStream) throws IOException {
ConfigSupport support = new ConfigSupport();
return support.fromJSON(inputStream);
}
/**
* Read config object stored in JSON format from <code>File</code>
*
* @param file
* @return
* @throws IOException
*/
public static Config fromJSON(File file) throws IOException {
ConfigSupport support = new ConfigSupport();
return support.fromJSON(file);
}
/**
* Read config object stored in JSON format from <code>URL</code>
*
* @param url
* @return
* @throws IOException
*/
public static Config fromJSON(URL url) throws IOException {
ConfigSupport support = new ConfigSupport();
return support.fromJSON(url);
}
/**
* Read config object stored in JSON format from <code>Reader</code>
*
* @param reader
* @return
* @throws IOException
*/
public static Config fromJSON(Reader reader) throws IOException {
ConfigSupport support = new ConfigSupport();
return support.fromJSON(reader);
}
public String toJSON() throws IOException {
ConfigSupport support = new ConfigSupport();
return support.toJSON(this);

@ -15,8 +15,12 @@
*/
package org.redisson;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.net.URI;
import java.net.URL;
import java.util.List;
import org.redisson.client.codec.Codec;
@ -99,6 +103,22 @@ public class ConfigSupport {
return mapper.readValue(content, Config.class);
}
public Config fromJSON(File file) throws IOException {
return mapper.readValue(file, Config.class);
}
public Config fromJSON(URL url) throws IOException {
return mapper.readValue(url, Config.class);
}
public Config fromJSON(Reader reader) throws IOException {
return mapper.readValue(reader, Config.class);
}
public Config fromJSON(InputStream inputStream) throws IOException {
return mapper.readValue(inputStream, Config.class);
}
public String toJSON(Config config) throws IOException {
return mapper.writeValueAsString(config);
}

@ -3,6 +3,8 @@ package org.redisson;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.redisson.client.codec.StringCodec;
import org.redisson.codec.MsgPackJacksonCodec;
public abstract class BaseTest {
@ -24,6 +26,7 @@ public abstract class BaseTest {
redisAddress = "127.0.0.1:6379";
}
Config config = new Config();
config.setCodec(new MsgPackJacksonCodec());
// config.useSentinelConnection().setMasterName("mymaster").addSentinelAddress("127.0.0.1:26379", "127.0.0.1:26389");
// config.useClusterServers().addNodeAddress("127.0.0.1:7004", "127.0.0.1:7001", "127.0.0.1:7000");
config.useSingleServer().setAddress(redisAddress);

Loading…
Cancel
Save