TopicSerialization { public static Map<ConfigResource, Config> toTopicConfig(Topic topic) { List<ConfigEntry> entries = new ArrayList<>(topic.getConfig().size()); for (Map.Entry<String, String> entry : topic.getConfig().entrySet()) { ConfigEntry configEntry = new ConfigEntry(entry.getKey(), entry.getValue()); entries.add(configEntry); } return Collections.singletonMap( new ConfigResource(ConfigResource.Type.TOPIC, topic.getTopicName().toString()), new Config(entries)); }  static Topic fromTopicResource(KafkaTopic kafkaTopic); static KafkaTopic toTopicResource(Topic topic, Labels labels); static NewTopic toNewTopic(Topic topic, Map<Integer, List<Integer>> assignment); static Map<ConfigResource, Config> toTopicConfig(Topic topic); static Topic fromTopicMetadata(TopicMetadata meta); static byte[] toJson(Topic topic); @SuppressWarnings("unchecked") static Topic fromJson(byte[] json); static final String JSON_KEY_TOPIC_NAME; static final String JSON_KEY_MAP_NAME; static final String JSON_KEY_PARTITIONS; static final String JSON_KEY_REPLICAS; static final String JSON_KEY_CONFIG; }
@Test public void testToTopicConfig() { Topic topic = new Topic.Builder() .withTopicName("test-topic") .withConfigEntry("foo", "bar") .withNumPartitions(3) .withNumReplicas((short) 2) .withMapName("gee") .build(); Map<ConfigResource, Config> config = TopicSerialization.toTopicConfig(topic); assertThat(config.size(), is(1)); Map.Entry<ConfigResource, Config> c = config.entrySet().iterator().next(); assertThat(c.getKey().type(), is(ConfigResource.Type.TOPIC)); assertThat(c.getValue().entries().size(), is(1)); assertThat(c.getKey().name(), is("test-topic")); assertThat(c.getValue().get("foo").value(), is("bar")); }