public static DataSchema dataMapToDataSchema(DataMap map, PegasusSchemaParser parser)
  {
    // Convert DataMap into DataSchema
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    JacksonDataCodec codec = new JacksonDataCodec();
    try
    {
      codec.writeMap(map, outputStream);
    }
    catch (IOException e)
    {
      // This should never occur
      throw new IllegalStateException(UNEXPECTED_IOEXCEPTION + map, e);
    }
    ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    parser.parse(inputStream);
    List<DataSchema> topLevelDataSchemas = parser.topLevelDataSchemas();
    assert(topLevelDataSchemas.size() <= 1);
    if (parser.hasError())
    {
      return null;
    }
    else if (topLevelDataSchemas.size() != 1)
    {
      // This should never occur
      throw new IllegalStateException(WRONG_NUMBER_OF_SCHEMA_LEFT + topLevelDataSchemas);
    }
    return topLevelDataSchemas.get(0);
  }
@Test
  public void testConvertDataMapToDataSchema() throws IOException
  {
    for (String good : goodInputs)
    {
      NamedDataSchema dataSchema = (NamedDataSchema) TestUtil.dataSchemaFromString(good);

      DataMap mapFromString = TestUtil.dataMapFromString(good);
      PegasusSchemaParser parser = new SchemaParser();
      DataSchema schemaFromMap = Conversions.dataMapToDataSchema(mapFromString, parser);

      assertEquals(schemaFromMap, dataSchema);
    }

    for (String bad : badInputs)
    {
      DataMap mapFromString = TestUtil.dataMapFromString(bad);
      PegasusSchemaParser parser = new SchemaParser();
      DataSchema schemaFromMap = Conversions.dataMapToDataSchema(mapFromString, parser);
      assertNull(schemaFromMap);
      assertTrue(parser.hasError());
    }
  }