use of com.fasterxml.jackson.databind.ObjectMapper in project spring-security by spring-projects.
the class CasAuthenticationTokenMixinTests method setup.
@Before
public void setup() {
mapper = new ObjectMapper();
ClassLoader loader = getClass().getClassLoader();
mapper.registerModules(SecurityJackson2Modules.getModules(loader));
}
use of com.fasterxml.jackson.databind.ObjectMapper in project buck by facebook.
the class OfflineScribeLoggerTest method unsentLinesStoredForOffline.
@Test
public void unsentLinesStoredForOffline() throws Exception {
final String whitelistedCategory = "whitelisted_category";
final String whitelistedCategory2 = "whitelisted_category_2";
final String blacklistedCategory = "blacklisted_category";
final ImmutableList<String> blacklistCategories = ImmutableList.of(blacklistedCategory);
final int maxScribeOfflineLogsKB = 7;
final ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
final Path logDir = filesystem.getBuckPaths().getOfflineLogDir();
final ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
String[] ids = { "test1", "test2", "test3", "test4" };
char[] longLineBytes = new char[1000];
Arrays.fill(longLineBytes, 'A');
String longLine = new String(longLineBytes);
char[] tooLongLineBytes = new char[6000];
Arrays.fill(longLineBytes, 'A');
String tooLongLine = new String(tooLongLineBytes);
// As we set max space for logs to 7KB, then we expect storing data with 2 'longLine' (which,
// given UTF-8 is used, will be ~ 2 * 1KB) to succeed. We then expect subsequent attempt to
// store data with 'tooLongLine' (~6KB) to fail. We also expect that logfile created by first
// fakeLogger ('test1' id) will be removed as otherwise data from last logger would not fit.
//
// Note that code sending already stored offline logs will be triggered by the first log() as
// it succeeds, but further failing log() (and initiating storing) will stop sending. Hence, no
// logs will be deleted due to the sending routine.
FakeFailingOfflineScribeLogger fakeLogger = null;
for (String id : ids) {
fakeLogger = new FakeFailingOfflineScribeLogger(blacklistCategories, maxScribeOfflineLogsKB, filesystem, logDir, objectMapper, new BuildId(id));
// Simulate network issues occurring for some of sending attempts (all after first one).
// Logging succeeds.
fakeLogger.log(whitelistedCategory, ImmutableList.of("hello world 1", "hello world 2"));
// Logging fails.
fakeLogger.log(whitelistedCategory, ImmutableList.of("hello world 3", "hello world 4"));
// Event with blacklisted category for offline logging.
fakeLogger.log(blacklistedCategory, ImmutableList.of("hello world 5", "hello world 6"));
// Logging fails.
fakeLogger.log(whitelistedCategory2, ImmutableList.of(longLine, longLine));
// Logging fails, but offline logging rejects data as well - too big.
fakeLogger.log(whitelistedCategory2, ImmutableList.of(tooLongLine));
fakeLogger.close();
}
// Check correct logs are in the directory (1st log removed).
Path[] expectedLogPaths = FluentIterable.from(ImmutableList.copyOf(ids)).transform(id -> filesystem.resolve(logDir.resolve(LOGFILE_PREFIX + id + LOGFILE_SUFFIX))).toArray(Path.class);
ImmutableSortedSet<Path> logs = filesystem.getMtimeSortedMatchingDirectoryContents(logDir, LOGFILE_PATTERN);
assertThat(logs, Matchers.allOf(hasItem(expectedLogPaths[1]), hasItem(expectedLogPaths[2]), hasItem(expectedLogPaths[3]), IsIterableWithSize.<Path>iterableWithSize(3)));
// Check that last logger logged correct data.
assertEquals(3, fakeLogger.getAttemptStoringCategoriesWithLinesCount());
InputStream logFile = fakeLogger.getStoredLog();
String[] whitelistedCategories = { whitelistedCategory, whitelistedCategory2 };
String[][] whitelistedLines = { { "hello world 3", "hello world 4" }, { longLine, longLine } };
Iterator<ScribeData> it = null;
try {
it = new ObjectMapper().readValues(new JsonFactory().createParser(logFile), ScribeData.class);
} catch (Exception e) {
fail("Obtaining iterator for reading the log failed.");
}
int dataNum = 0;
try {
while (it.hasNext()) {
assertTrue(dataNum < 2);
ScribeData data = it.next();
assertThat(data.getCategory(), is(whitelistedCategories[dataNum]));
assertThat(data.getLines(), Matchers.allOf(hasItem(whitelistedLines[dataNum][0]), hasItem(whitelistedLines[dataNum][1]), IsIterableWithSize.<String>iterableWithSize(2)));
dataNum++;
}
} catch (Exception e) {
fail("Reading stored offline log failed.");
}
logFile.close();
assertEquals(2, dataNum);
}
use of com.fasterxml.jackson.databind.ObjectMapper in project Gaffer by gchq.
the class HyperLogLogPlusJsonSerialisationTest method before.
@Before
public void before() {
mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
final SimpleModule module = new SimpleModule(HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SERIALISER_MODULE_NAME, new Version(1, 0, 0, null));
module.addSerializer(HyperLogLogPlus.class, new HyperLogLogPlusJsonSerialiser());
module.addDeserializer(HyperLogLogPlus.class, new HyperLogLogPlusJsonDeserialiser());
mapper.registerModule(module);
}
use of com.fasterxml.jackson.databind.ObjectMapper in project Gaffer by gchq.
the class GraphConfigurationService method getSerialisedFields.
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user")
@Override
public Set<String> getSerialisedFields(final String className) {
final Class<?> clazz;
try {
clazz = Class.forName(className);
} catch (final Exception e) {
throw new IllegalArgumentException("Class name was not recognised: " + className, e);
}
final ObjectMapper mapper = new ObjectMapper();
final JavaType type = mapper.getTypeFactory().constructType(clazz);
final BeanDescription introspection = mapper.getSerializationConfig().introspect(type);
final List<BeanPropertyDefinition> properties = introspection.findProperties();
final Set<String> fields = new HashSet<>();
for (final BeanPropertyDefinition property : properties) {
fields.add(property.getName());
}
return fields;
}
use of com.fasterxml.jackson.databind.ObjectMapper in project camel by apache.
the class RestSwaggerReaderApiDocsOverrideTest method testReaderRead.
@Test
public void testReaderRead() throws Exception {
BeanConfig config = new BeanConfig();
config.setHost("localhost:8080");
config.setSchemes(new String[] { "http" });
config.setBasePath("/api");
RestSwaggerReader reader = new RestSwaggerReader();
Swagger swagger = reader.read(context.getRestDefinitions(), null, config, context.getName(), new DefaultClassResolver());
assertNotNull(swagger);
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String json = mapper.writeValueAsString(swagger);
log.info(json);
assertFalse(json.contains("\"/hello/bye\""));
assertFalse(json.contains("\"summary\" : \"To update the greeting message\""));
assertTrue(json.contains("\"/hello/bye/{name}\""));
assertFalse(json.contains("\"/hello/hi/{name}\""));
context.stop();
}
Aggregations