<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to deserialize a JSON symbol definition in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-deserialize-a-json-symbol-definition/m-p/1006813#M5809</link>
    <description>&lt;P&gt;I am trying to create a CIMUniqueValueRenderer from a table that contains JSON symbol definitions. The symbol definitions in that table were pulled from a stylx file.&lt;/P&gt;&lt;P&gt;I am trying to use CIMSymbolReference.FromJson() to deserialize each symbol definition, but it keeps failing with the cryptic error "Wrong type name". The documentation here is failing me.&lt;/P&gt;&lt;P&gt;A typical JSON string looks like this:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;"{\"type\":\"CIMLineSymbol\",\"symbolLayers\":[{\"type\":\"CIMSolidStroke\",\"enable\":true,\"colorLocked\":true,\"primitiveName\":\"1.0\",\"capStyle\":\"Butt\",\"joinStyle\":\"Round\",\"lineStyle3D\":\"Strip\",\"miterLimit\":10,\"width\":0.43086614173228349,\"color\":{\"type\":\"CIMCMYKColor\",\"values\":[0,0,0,100,100]}}]}"&lt;/LI-CODE&gt;&lt;P&gt;Can anyone tell me why CIMSymbolReference.FromJson() chokes on this?&lt;/P&gt;&lt;P&gt;Is there another way to get from a JSON symbol definition to a symbol I can use in a CIMUniqueValueClass?&lt;/P&gt;&lt;P&gt;Code excerpt:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =&amp;gt; {

	using (Geodatabase geodatabase = new Geodatabase(DataHelper.connectionProperties)) {

		QueryDef cfQDef = new QueryDef {
			Tables = "CFSymbology",
			PostfixClause = "order by key"
		};

		using (RowCursor rowCursor = geodatabase.Evaluate(cfQDef, false)) {
			List&amp;lt;CIMUniqueValueClass&amp;gt; listUniqueValueClasses = new List&amp;lt;CIMUniqueValueClass&amp;gt;();
			while (rowCursor.MoveNext()) {
				using (Row row = rowCursor.Current) {
					Debug.WriteLine(row["key"].ToString());

					//create and load map unit
					var cf = new CF();
					cf.key = row["key"].ToString();
					cf.symbol = row["symbol"].ToString();

					//add it to our list
					cfs.Add(cf);

					//Create a "CIMUniqueValueClass" for the symbol and add it to the list of unique values.
					//This is what creates the mapping from map unit to color
					List&amp;lt;CIMUniqueValue&amp;gt; listUniqueValues = new List&amp;lt;CIMUniqueValue&amp;gt; {
							new CIMUniqueValue {
								FieldValues = new string[] { cf.key }
							}
					};
					CIMUniqueValueClass uniqueValueClass = new CIMUniqueValueClass {
						Editable = true,
						Label = cf.key,
						//Patch = PatchShape.Default,
						Patch = PatchShape.AreaPolygon,
						Symbol = CIMSymbolReference.FromJson(cf.symbol, null),
						Visible = true,
						Values = listUniqueValues.ToArray()
					};
					listUniqueValueClasses.Add(uniqueValueClass);

				}
			}

			//Create a list of CIMUniqueValueGroup
			CIMUniqueValueGroup uvg = new CIMUniqueValueGroup {
				Classes = listUniqueValueClasses.ToArray(),
			};
			List&amp;lt;CIMUniqueValueGroup&amp;gt; listUniqueValueGroups = new List&amp;lt;CIMUniqueValueGroup&amp;gt; { uvg };

			//Use the list to create the CIMUniqueValueRenderer
			DataHelper.cfRenderer = new CIMUniqueValueRenderer {
				UseDefaultSymbol = false,
				Groups = listUniqueValueGroups.ToArray(),
				Fields = new string[] { "key" }
			};

			//Set renderer in contactsandfaults layer. The try/catch is there because the first time through, this is called 
			//before the layer has been added to the map. We just ignore the error in that case.
			try {
				var cfLayer = MapView.Active.Map.GetLayersAsFlattenedList().First((l) =&amp;gt; l.Name == "ContactsAndFaults") as FeatureLayer;
				cfLayer.SetRenderer(DataHelper.cfRenderer);
			} catch { }

		}

	}
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Dec 2020 22:02:23 GMT</pubDate>
    <dc:creator>Douglas_DMeredith</dc:creator>
    <dc:date>2020-12-03T22:02:23Z</dc:date>
    <item>
      <title>How to deserialize a JSON symbol definition</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-deserialize-a-json-symbol-definition/m-p/1006813#M5809</link>
      <description>&lt;P&gt;I am trying to create a CIMUniqueValueRenderer from a table that contains JSON symbol definitions. The symbol definitions in that table were pulled from a stylx file.&lt;/P&gt;&lt;P&gt;I am trying to use CIMSymbolReference.FromJson() to deserialize each symbol definition, but it keeps failing with the cryptic error "Wrong type name". The documentation here is failing me.&lt;/P&gt;&lt;P&gt;A typical JSON string looks like this:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;"{\"type\":\"CIMLineSymbol\",\"symbolLayers\":[{\"type\":\"CIMSolidStroke\",\"enable\":true,\"colorLocked\":true,\"primitiveName\":\"1.0\",\"capStyle\":\"Butt\",\"joinStyle\":\"Round\",\"lineStyle3D\":\"Strip\",\"miterLimit\":10,\"width\":0.43086614173228349,\"color\":{\"type\":\"CIMCMYKColor\",\"values\":[0,0,0,100,100]}}]}"&lt;/LI-CODE&gt;&lt;P&gt;Can anyone tell me why CIMSymbolReference.FromJson() chokes on this?&lt;/P&gt;&lt;P&gt;Is there another way to get from a JSON symbol definition to a symbol I can use in a CIMUniqueValueClass?&lt;/P&gt;&lt;P&gt;Code excerpt:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =&amp;gt; {

	using (Geodatabase geodatabase = new Geodatabase(DataHelper.connectionProperties)) {

		QueryDef cfQDef = new QueryDef {
			Tables = "CFSymbology",
			PostfixClause = "order by key"
		};

		using (RowCursor rowCursor = geodatabase.Evaluate(cfQDef, false)) {
			List&amp;lt;CIMUniqueValueClass&amp;gt; listUniqueValueClasses = new List&amp;lt;CIMUniqueValueClass&amp;gt;();
			while (rowCursor.MoveNext()) {
				using (Row row = rowCursor.Current) {
					Debug.WriteLine(row["key"].ToString());

					//create and load map unit
					var cf = new CF();
					cf.key = row["key"].ToString();
					cf.symbol = row["symbol"].ToString();

					//add it to our list
					cfs.Add(cf);

					//Create a "CIMUniqueValueClass" for the symbol and add it to the list of unique values.
					//This is what creates the mapping from map unit to color
					List&amp;lt;CIMUniqueValue&amp;gt; listUniqueValues = new List&amp;lt;CIMUniqueValue&amp;gt; {
							new CIMUniqueValue {
								FieldValues = new string[] { cf.key }
							}
					};
					CIMUniqueValueClass uniqueValueClass = new CIMUniqueValueClass {
						Editable = true,
						Label = cf.key,
						//Patch = PatchShape.Default,
						Patch = PatchShape.AreaPolygon,
						Symbol = CIMSymbolReference.FromJson(cf.symbol, null),
						Visible = true,
						Values = listUniqueValues.ToArray()
					};
					listUniqueValueClasses.Add(uniqueValueClass);

				}
			}

			//Create a list of CIMUniqueValueGroup
			CIMUniqueValueGroup uvg = new CIMUniqueValueGroup {
				Classes = listUniqueValueClasses.ToArray(),
			};
			List&amp;lt;CIMUniqueValueGroup&amp;gt; listUniqueValueGroups = new List&amp;lt;CIMUniqueValueGroup&amp;gt; { uvg };

			//Use the list to create the CIMUniqueValueRenderer
			DataHelper.cfRenderer = new CIMUniqueValueRenderer {
				UseDefaultSymbol = false,
				Groups = listUniqueValueGroups.ToArray(),
				Fields = new string[] { "key" }
			};

			//Set renderer in contactsandfaults layer. The try/catch is there because the first time through, this is called 
			//before the layer has been added to the map. We just ignore the error in that case.
			try {
				var cfLayer = MapView.Active.Map.GetLayersAsFlattenedList().First((l) =&amp;gt; l.Name == "ContactsAndFaults") as FeatureLayer;
				cfLayer.SetRenderer(DataHelper.cfRenderer);
			} catch { }

		}

	}
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2020 22:02:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-deserialize-a-json-symbol-definition/m-p/1006813#M5809</guid>
      <dc:creator>Douglas_DMeredith</dc:creator>
      <dc:date>2020-12-03T22:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to deserialize a JSON symbol definition</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-deserialize-a-json-symbol-definition/m-p/1007008#M5814</link>
      <description>&lt;P&gt;Hi Douglas,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;CIMSymbolReference.FromJson() can only de-serialize JSON that contains a&amp;nbsp;CIMSymbolReference object.&amp;nbsp; The message&amp;nbsp;"Wrong type name" refers the type that has been serialized into your JSON string:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
  "type": "CIMLineSymbol",
  ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you look at the serialized JSON for a&amp;nbsp;&lt;SPAN&gt;CIMSymbolReference you should see a JSON string looking like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;{
  "type": "CIMSymbolReference",
  "symbol": {
    "type": "CIMPolygonSymbol",
    "symbolLayers": [
      {
        "type": "CIMSolidStroke",
        "enable": true,
        "capStyle": "Round",
        "joinStyle": "Round",
        "lineStyle3D": "Strip",
        "miterLimit": 10,
        "width": 1,
        "color": {
          "type": "CIMRGBColor",
          "values": [
            0,
            0,
            0,
            100
          ]
        }
      },
      {
        "type": "CIMSolidFill",
        ....&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 17:43:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-deserialize-a-json-symbol-definition/m-p/1007008#M5814</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2020-12-04T17:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to deserialize a JSON symbol definition</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-deserialize-a-json-symbol-definition/m-p/1007097#M5823</link>
      <description>&lt;P&gt;Thanks for pointing this out. Wrapping the symbol JSON string with the CIMSymbolReference JSON string bits gets the job done.&lt;/P&gt;&lt;P&gt;It's not very elegant though. It would be nice if there were a FromJson() routine in CIMSymbol.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 22:02:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-deserialize-a-json-symbol-definition/m-p/1007097#M5823</guid>
      <dc:creator>Douglas_DMeredith</dc:creator>
      <dc:date>2020-12-04T22:02:42Z</dc:date>
    </item>
  </channel>
</rss>

